(Inportant function of Binary Tree)
 
Line 1: Line 1:
//Inportant function of Binary Tree
+
[[Category:PeerLegacy]]
 +
= [[Peer_legacy |Peer Legacy]] for [[ECE264]]: "Advance C Programming" =
 +
All students who have previously taken ECE264 are welcome to use this page to leave comments/give advice to future students.
  
 +
*Write a comment here. Sign your name/nickname.
 +
*Write a comment here. Sign your name/nickname.
 +
----
 +
[[Peer_legacy|Back to Peer Legacy Page]]
  
typedef struct TreeNode_t {
+
[[ECE264|Back to ECE264]]
  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;
+
}
+

Latest revision as of 05:20, 11 July 2012

Peer Legacy for ECE264: "Advance C Programming"

All students who have previously taken ECE264 are welcome to use this page to leave comments/give advice to future students.

  • Write a comment here. Sign your name/nickname.
  • Write a comment here. Sign your name/nickname.

Back to Peer Legacy Page

Back to ECE264

Alumni Liaison

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett