Print out all of its root-to-leaf paths of a binary tree .

Paths for below tree are : A – B – D A – C – E   Algorithm :

 initialize: pathlen = 0,  <a href="">Air Max Goedkoop</a> path[500] //500 for max length of tree path /*printPaths traverses nodes of tree in preorder */ printPaths(tree,  <a href="">nike air max 90 pas cher</a> path[], pathlen) 1) If node is not NULL then a) push data to path array: path[pathlen] = node-&gt;data. b) increment pathlen pathlen++ 2) If node is a leaf node then print the path array. 3) Else a) Call printPaths for left subtree printPaths(node-&gt;left, path,  <a href="">Fjallraven Kanken Big</a> pathLen) b) Call printPaths for right subtree. printPaths(node-&gt;right,  <li><a href="">Nike Air Max 90 Dames zwart</a></li> path,  <li><a href="">Adidas Superstar Blu Donna</a></li> pathLen) 

Code :

 void printPaths(struct node* node) { int path[500]; printPathsRecur(node, path,  sac a dos fjallraven soldes 0); } void printArray(int ints[], int len) { int i; for (i=0; i<len; i++) { printf("%d ",  nike basketball shoes for sale in south africa ints[i]); } printf("\n"); } /* Recursive function -- */ void printPathsByRecur(struct node* node, int path[],  nike internationalist donna int pathLen) { if (node==NULL) return; /* append this node to the path array */ path[pathLen] = node->data; pathLen++; /* it's a leaf, so print the path that led to here */ if (node->left==NULL && node->right==NULL) { printArray(path, pathLen); } else { printPathsByRecur(node->left,  

  • ROSHE LD-1000 QS
  • path, pathLen); printPathsByRecur(node->right, Adidas buty sklep path,

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    For Inserting code :
    Paste your code in the comment form, select it and then click the language link

    C | C++ | Java |