Please Try to Correct it Its Showing Segmentation fault...Reply ASAP... its code for the above program might be not designed in same way...what question..asking ..but i tried..it....Try to make is Clear & Executable ...
consider tree below 1 / \ 1 0 / \ / \ 1 0 1 0 / \ / \ 0 0 0 0 #include <stdio.h> #include <stdlib.h> /* A binary tree node has data, pointer to left child and a pointer to right child */ struct node { int data; struct node* left; struct node* right; }; /* Given a binary tree, print its nodes in inorder*/ void printPreorder(struct node* node) { if (node == NULL) return; /* first print data of node */ printf("%d ", node->data); /* then recur on left sutree */ printPreorder(node->left); /* now recur on right subtree */ printPreorder(node->right); } struct node* newNode(int data) { struct node* node = (struct node*) malloc(sizeof(struct node)); node->data = data; node->left = NULL; node->right = NULL; return(node); } struct node* build_CBT(struct node *root) { struct node *node=root; if(node==NULL) { printf(" Special Tree Yes"); return; } if(node!=NULL) { node->data=newNode(1); if(node->left ==NULL && node->right==NULL) { node->left->data=node->right->data=newNode(0); return; } } else { if(node->left!=NULL) { //node->left->data=N; build_CBT(node->left); } if(node->right!=NULL) { //put(node->right->data=N; build_CBT(node->right); } } return node; } /*Driver program to test above functions*/ int main() { /*create a tree*/ struct node *root=(struct node *)malloc(sizeof(struct node)*9); root=build_CBT(root); printPreorder(root); getchar(); return 0; } Thanks & Regards Shashank Mani "The Best Way To Escape From The Problem is to Solve it " -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.