Line 1: Line 1:
[[Category:ECE264]]
+
<br>
  
=Binary Tree: In Order and Post Order=
+
= Binary Tree: In Order and Post Order =
 +
'''In Order Printing'''
 +
In order printing takes the root of a binary tree and prints all the values in the tree in order. &nbsp;The function is a recursive function that goes as far left in the binary tree until it hits the end. &nbsp;It will then print the leaf's value. &nbsp;After the leaf's value is printed, the function moves to the right once and precedes to go left until a leaf is found. &nbsp;Printing the leaf's value and continues on.
  
  
  
Put your content here . . .
+
Example code for in order printing:
  
 +
void Tree_inOrder(TNode *n) /*see declaration of TNode below*/
  
 +
{
  
 +
&nbsp;&nbsp; &nbsp; if(n==0)
  
[[ ECE264|Back to ECE264]]
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;
 +
 
 +
&nbsp;&nbsp; &nbsp; Tree_inOrder(n-&gt;left);
 +
 
 +
&nbsp;&nbsp; &nbsp; printf("%d\n", n-&gt;value);
 +
 
 +
&nbsp;&nbsp; &nbsp; Tree_inOrder(n-&gt;right);
 +
 
 +
}&nbsp;
 +
 
 +
<br>
 +
 
 +
void Tree_postOrder(TNode *n) /*see declaration of TNode below*/
 +
 
 +
{
 +
 
 +
&nbsp;&nbsp; &nbsp; if(n==0)
 +
 
 +
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 +
 
 +
&nbsp;&nbsp; &nbsp; Tree_postOrder(n-&gt;left);
 +
 
 +
&nbsp;&nbsp; &nbsp; Tree_postOrder(n-&gt;right);
 +
 
 +
&nbsp;&nbsp; &nbsp; printf("%d\n", n-&gt;value);
 +
 
 +
}
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
The declaration of TNode is as followed:
 +
 
 +
typedef struct Treenode
 +
 
 +
{
 +
 
 +
&nbsp;&nbsp; &nbsp; int value;
 +
 
 +
&nbsp;&nbsp; &nbsp; struct Treenode *left;
 +
 
 +
&nbsp;&nbsp; &nbsp; struct Treenode *right;
 +
 
 +
}TNode;
 +
 
 +
<br> [[ECE264|Back to ECE264]]
 +
 
 +
[[Category:ECE264]]

Revision as of 17:11, 28 April 2011


Binary Tree: In Order and Post Order

In Order Printing In order printing takes the root of a binary tree and prints all the values in the tree in order.  The function is a recursive function that goes as far left in the binary tree until it hits the end.  It will then print the leaf's value.  After the leaf's value is printed, the function moves to the right once and precedes to go left until a leaf is found.  Printing the leaf's value and continues on.


Example code for in order printing:

void Tree_inOrder(TNode *n) /*see declaration of TNode below*/

{

     if(n==0)

           return;

     Tree_inOrder(n->left);

     printf("%d\n", n->value);

     Tree_inOrder(n->right);


void Tree_postOrder(TNode *n) /*see declaration of TNode below*/

{

     if(n==0)

          return;

     Tree_postOrder(n->left);

     Tree_postOrder(n->right);

     printf("%d\n", n->value);

}




The declaration of TNode is as followed:

typedef struct Treenode

{

     int value;

     struct Treenode *left;

     struct Treenode *right;

}TNode;


Back to ECE264

Alumni Liaison

Sees the importance of signal filtering in medical imaging

Dhruv Lamba, BSEE2010