/** * Based on understanding gained from online resources as detailed in the * bibliography of my writeup * * Simple function that performs an in order traverse on the binary tree * performing a function passed in as a pointer for each node examined. * * @param node the current node being examined, the root node is passed in * originally * @param function a pointer to a function that should be performed on each node */ void in_order_traverse(competitor * node, void(*function)(competitor*)){ if(node != NULL){ in_order_traverse(node->left, function); function(node); in_order_traverse(node->right, function); } }
void in_order_traverse(BiTree T){ if (T == NULL) return; in_order_traverse(T->lchild); printf("%d ",T->data); in_order_traverse(T->rchild); }
void in_order_traverse(TreeNode *root, int val) { if (root == NULL || succ != NULL) return; in_order_traverse(root->left, val); if (pred != NULL && pred->val == val) { succ = root; } pred = root; in_order_traverse(root->right, val); }
/** * * \brief * Inoder traverse a binary tree * * \param root The root of a binary tree (input) * * \return none. * */ void in_order_traverse(BiNode *root) { if(NULL == root) { return; } in_order_traverse(root->lchild); printf("%s\t", root->name); in_order_traverse(root->rchild); }
/* * 递归 * 中序遍历:先遍历左子树,然后显示结点数据,再遍历右子树 */ void in_order_traverse(struct avl *tree) { if (tree == NULL) return; /* traverse left tree */ in_order_traverse(tree->lchild); /* show the node data */ printf("[%i]", tree->data); /* traverse right tree */ in_order_traverse(tree->rchild); }
int main() { node_t * root = bitree::read<pnode>(); init(root); in_order_traverse(root); bitree::free(root); return 0; }
int main(int argc, char *argv[]) { int i; int a[10] = {3, 2, 1, 4, 5, 6, 7, 20, 16, 10}; struct avl *tree = NULL; int taller = 0; for (i = 0; i < 10; ++i) insert_avl(&tree, a[i], &taller); in_order_traverse(tree); printf("\nAfter insert 12:\n"); insert_avl(&tree, 12, &taller); in_order_traverse(tree); printf("\n"); return 0; }
/** * calls the various other printing functions to perform the printing of the * results * * @param competition the competition struct containing the name and date of the * competition * @param root */ void print_results(competition competition, competitor * root){ print_competition_header(competition); print_results_header(); in_order_traverse(root, print_results_inner); printf("\n\n"); }
/** * calls all the necessary functions to correctly print all the contact * details information in the right format * * @param competition struct storing name and date of competition * @param root */ void print_contact_details(competition competition, competitor * root){ print_competition_header(competition); print_contact_details_header(); in_order_traverse(root, print_contact_details_inner); }
TreeNode *in_order_successor(TreeNode *root, int val) { pred = succ = NULL; in_order_traverse(root, val); return succ; }