Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,230 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,868 people online right now. Registration is fast and FREE... Join Now!




trees c++ help!

 
Reply to this topicStart new topic

trees c++ help!

devilbolt
11 Mar, 2007 - 12:41 AM
Post #1

New D.I.C Head
*

Joined: 5 Feb, 2007
Posts: 9


My Contributions
Suppose you are given the preorder sequence of a binary tree containing distinct char
objects stored in an array pre[preS..preE], and the inorder sequence of the same binary
tree stored in another array in[inS..inE].

Write a recursive function that returns the binary
tree represented by these sequences (this binary tree is unique).
you may use the following function prototype, which returns the root of the tree:
TreeNode constructTree(int preS, int preE, char[] pre,
int inS, int inE, char[] in) {
// function implementation
}

help help i dunno how to approach this question/!

This post has been edited by devilbolt: 11 Mar, 2007 - 12:42 AM
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Trees C++ Help!
13 Mar, 2007 - 11:03 AM
Post #2

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
Binary tree means
CODE

          node
         /       \    
   node         node    
  /     \        /      \
node node node node
/    \  etc...

So each node consists of pointers to the left and right nodes below it and a payload.
Without the payload there would be no point. Here is a very basic binary tree node.

CODE

template <class T>
class node {
  public:
  node *right;
  node *left;
  T payload;  
};


You could get rid of the template and define a type if you would like.
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Trees C++ Help!
13 Mar, 2007 - 11:12 AM
Post #3

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
You only need the tree parts of this for now, but the rest may be useful soon.

http://ww3.algorithmdesign.net/handouts/DataStructures.pdf
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:17PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month