Reconstruct BST using postorder traversal.

Given postorder traversal array of a BST, recontruct the BST.

C++:
01 Node* constructBST(int A[], int& end, int min)
02 {
03     if((end<0)||(A[end]<min))
04         return NULL;
05     Node* head=new Node;
06     int data=A[end];
07     head->value=data;
08     head->right=constructBST(A,end,data);
09     head->left=constructBST(A,end,min);
10     return head;
11 }
Advertisements
This entry was posted in Recursive, Tree. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s