Advertisement
elica123

Untitled

Nov 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. struct node* buildTree(char in[], char pre[], int inStrt, int inEnd)
  2. {
  3. static int preIndex =(sizeof(pre)/sizeof(pre[0]))-1; //zadnji u postorderu je korjen
  4.  
  5. if(inStrt > inEnd)
  6. {
  7. return NULL;}
  8.  
  9. struct node *tNode = newNode(pre[preIndex--]); //krecem se od iza zbog defiicje postordera
  10.  
  11.  
  12. if(inStrt == inEnd) //tu nam je bazicni slucaj
  13. return tNode;
  14.  
  15.  
  16. int inIndex = search(in, inStrt, inEnd, tNode->data);
  17. tNode->left= buildTree(in, pre, inStrt, inIndex-1);
  18. tNode->right = buildTree(in, pre, inIndex+1, inEnd);
  19. return tNode;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement