Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- struct node_el{
- struct node *left_child;
- struct node *right_child;
- struct node *root;
- int index;
- };
- typedef struct node_el node;
- int spurt_hole(node *start){
- if (start->left_child != NULL && start->right_child !=NULL){
- printf("index %d has children on right and left\n", start->index);
- spurt_hole(start->left_child);
- spurt_hole(start->right_child);
- }
- else{
- if (start->left_child != NULL){
- printf ("index %d left but not right\n", start->index);
- spurt_hole(start->left_child);
- return;
- }
- if (start->right_child !=NULL){
- printf("index %d right but not left\n", start->index);
- spurt_hole(start->right_child);
- return;
- }
- printf("index %d has neither children\n", start->index);
- return;
- }
- return;
- }
- int initialize_node(node *sample, node *rooter){
- sample->left_child = NULL;
- sample->right_child = NULL;
- sample->index = 0;
- sample->root= rooter;
- }
- void main() {
- int i;
- node *rooter;
- node *temp1;
- node *temp2;
- node *root_ptr;
- rooter = (node *)malloc(sizeof(node));
- root_ptr = rooter;
- printf("initializing unbalanced tree");
- for (i=0; i<20; i++){
- printf("%d\n",i);
- temp1 = (node *) malloc(sizeof(node));
- temp2 = (node *) malloc(sizeof(node));
- initialize_node(temp1,rooter);
- initialize_node(temp2,rooter);
- temp1->index = i;
- temp2->index = 22;
- rooter->left_child = temp1;
- rooter->right_child = temp2;
- rooter = temp1;
- }
- spurt_hole(root_ptr);
- }
Add Comment
Please, Sign In to add comment