Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BINARY SEARCH TREE IN C++

Posted on 2003-11-15
5
Medium Priority
?
680 Views
Last Modified: 2010-04-02
HELLO, HOW DO I USE CLASSES IN CPP TO CREATE A BINARY SEARCH TREE, PLEASE GIVE ME A PERFECT **SIMPLE** EXAMPLE OF USING CLASSES TO CREATE A BINARY SEARCH TREE.  THANK YOU
0
Comment
Question by:needle176
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 11

Expert Comment

by:bcladd
ID: 9759070
Doing homework for someone is against the membership agreement (as is asking for homework solutions). Show us what you know how to do in C++. Where are you getting stuck? What are the objects in your program. That is, are you looking to create a BST objcect or a BST _OF_ objects or BOTH? Again, show us where you are in understanding the problem and we can help you figure out how to procede.

Note that in any case you are asking for a lot for 20 points.

-bcl
0
 

Expert Comment

by:rrattani
ID: 9764205
A complete Binary Search Tree for just 20 pts. U must be kidding.
0
 
LVL 9

Expert Comment

by:jhshukla
ID: 9767863
I will show u how data in a node of the BST looks like and how to use it in a BST. no more than that for 20 pts.

WARNING: There could be many syntactical errors in this example. if there are they all should be of the same kind: misplacing "templatizers".

template <class T>
class Node<T>{
  Node<T>::Node();
  T data;
  Node<T> *left_child, *right_child, *parent;
};

template<class T>
Node<T>::Node(Node<T> *l=NULL, T &d=T(),
                         Node<T> *r=NULL, Node<T> *p=NULL)
  :left_child(l), data(d), right_child(r), parent(p)
{}

//***********************************************//

template <class T>
class BST<T>{
  ...
  Node<T> *root;
};

template<class T>
BST<T>::BST(){
  root = NULL;
}

//***********************************************//

**NOTE**
1. The Node at which 'root' is pointing is the parent of all nodes in the tree. if root == NULL, the tree is considered empty and to have a height of -1.
2. The root node's parent must ALWAYS be NULL. you can temporarily change it for your program but be sure that you set it to NULL before you exit the function/method.

you will have to figure out algorithms for searching and moving date around in the BST without violating the property. there are many webpages that explain it very clearly. note that those pages will moslty contain algorithms or pseudo code. how to use them in C++? do it yourself. :)

Hope that buys me 20 pts.

0
 
LVL 9

Expert Comment

by:tinchos
ID: 10249249
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ - no points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10308121
PAQed - no points refunded (of 20)

modulo
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question