Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 39 void foreach(itemt const *root, void (*func)(int)){
- 40 itemt const *cur = root;
- 41 func(cur->value);
- 42 if (cur->left){
- 43 foreach(cur->left, func);
- 44 }
- 45 if (cur->right){
- 46 foreach(cur->right, func);
- 47 }
- 48 }
- 49
- 50 itemt* map(itemt const *root, int (*func)(int)){
- 51 itemt const *cur = root;
- 52 itemt *new_list = tree_new(func(cur->value));
- 53 if (cur->left){
- 54 new_list->left = map(cur->left, func);
- 55 }
- 56 if (cur->right){
- 57 new_list->right = map(cur->right, func);
- 58 }
- 59 return new_list;
- 60 }
- 61
- 62 int foldl(itemt const *root, int (*func)(int, int), int acc){
- 63 itemt const *cur = root;
- 64 if (cur->left){
- 65 acc = foldl(cur->left, func, acc);
- 66 }
- 67 if (cur->right){
- 68 acc = foldl(cur->right, func, acc);
- 69 }
- 70 acc = func(cur->value, acc);
- 71 return acc;
- 72 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement