Revision as of 04:42, 11 July 2012 by Rhea (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Important function of Binary Tree

typedef struct TreeNode_t {

 int valude;
 struct TreeNode_t *left, *right;


}TreeNode;


TreeNode *TreeNode_create(int value) {

 TreeNode *node = malloc(sizeof(TreeNode));
 Node->value=value;
 node->left=NULL;
 node->right=NULL;
 return node;

}


TreeNode *Tree_insert(TreeNode *node, int value) {

 if (node==NULL)
   return TreeNode_create(value);
 if(node->value>=value)
   node->left=Tree_insert(node->left,value);
 else
   node->right=Tree_insert(node->right,value);
 return node;


}

void Tree_inorder(TreeNode *node) {

 if (node==NULL)
   return ;
 Tree_inorder(node->left);
 printf("%d\n",node->value);
 Tree_inorder(node->right);


}


int main(int argc, char *argc[]) {

 if(argc!=3)
   {
     return EXIT_FAILURE;
   }
 FILE *f=fopen(argv[1],"r");
 if (f==NULL)
   {
     return EXIT_FAILURE;
   }
 int num;
 TreeNode *root=NULL;
 while(fscanf(f,"%d",&sum)==1)
   {
     root = Tree_insert(root,num);
   }

fclose(f); Tree_inorder(root);

return EXIT_FAILURE; }


Back to ECE264

Alumni Liaison

Abstract algebra continues the conceptual developments of linear algebra, on an even grander scale.

Dr. Paul Garrett