+Example of Binary Tree from
+Fundamentals of data structures in C.
+2nd ed., Silicon Press, 2008, pp. 204-205.
+Written by Junhwi Kim <junhwi.kim23@gmail.com>
+#define MAX_STACK_SIZE 100
+#define MAX_QUEUE_SIZE 100
+typedef struct node *tree_pointer;
+ tree_pointer left_child, right_child;
+void inorder (tree_pointer ptr)
+/* inorder tree traversal */
+ inorder(ptr->left_child);
+ printf("%d", ptr->data);
+ inorder(ptr->right_child);
+void preorder (tree_pointer ptr)
+/* preorder tree traversal */
+ printf("%d", ptr->data);
+ inorder(ptr->left_child);
+ inorder(ptr->right_child);
+void postorder (tree_pointer ptr)
+/* postorder tree traversal */
+ inorder(ptr->left_child);
+ inorder(ptr->right_child);
+ printf("%d", ptr->data);
+void iter_inorder(tree_pointer node)
+ tree_pointer stack[MAX_STACK_SIZE];
+ for(; node; node = node->left_child) {
+ printf("%d", node->data);
+ node = node->right_child;
+void level_order(tree_pointer ptr)
+/* level order tree traversal */
+ tree_pointer queue[MAX_QUEUE_SIZE];
+ printf("%d", ptr->data);
+ queue[++rear] = ptr->left_child;
+ queue[++rear] = ptr->right_child;
+tree_pointer search(tree_pointer root, int key)
+/* return a pointer to the element whose key is k,
+if there is no such element, return NULL. */
+ if (!root) return NULL;
+ if (key == root->data) return root;
+ return search(root->left_child, key);
+ return search(root->right_child, key);
+tree_pointer iter_search(tree_pointer tree, int k)
+ if (k == tree->data) return tree;
+ tree = tree->left_child;
+ tree = tree->right_child;