/*-------------------------------------------------------------------*/ /* fall03exam2q1intel.c */ /*-------------------------------------------------------------------*/ #include #include struct tree { int key; struct tree *left; struct tree *right; }; void clearkeys(struct tree *t); /*-------------------------------------------------------------------*/ void printkeys(struct tree *t) /* Print all of the integers in t to stdout. */ { if (t != NULL) { printkeys(t->left); printf("%d\n", t->key); printkeys(t->right); } } /*-------------------------------------------------------------------*/ int main(void) /* Create a three-level tree containing integers, print the tree to stdout, set all of the integers to 0, and print the tree again. */ { struct tree *mytree; mytree = (struct tree*)malloc(sizeof(struct tree)); mytree->key = 4; mytree->left = (struct tree*)malloc(sizeof(struct tree)); mytree->right = (struct tree*)malloc(sizeof(struct tree)); mytree->left->key = 2; mytree->left->left = (struct tree*)malloc(sizeof(struct tree)); mytree->left->right = (struct tree*)malloc(sizeof(struct tree)); mytree->right->key = 6; mytree->right->left = (struct tree*)malloc(sizeof(struct tree)); mytree->right->right = (struct tree*)malloc(sizeof(struct tree)); mytree->left->left->key = 1; mytree->left->left->left = NULL; mytree->left->left->right = NULL; mytree->left->right->key = 3; mytree->left->right->left = NULL; mytree->left->right->right = NULL; mytree->right->left->key = 5; mytree->right->left->left = NULL; mytree->right->left->right = NULL; mytree->right->right->key = 7; mytree->right->right->left = NULL; mytree->right->right->right = NULL; printkeys(mytree); clearkeys(mytree); printkeys(mytree); return 0; }