Binary Search Tree

Binary Tree Search

Page 1 of 1

5 Replies - 4139 Views - Last Post: 20 April 2010 - 12:27 PM Rate Topic: -----

#1 Jmaurice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-October 09

Binary Search Tree

Posted 18 April 2010 - 04:52 PM

i was wondering how would you do insert function without using recursion. i know who to do it with recursion

// In C++
I have to write a class for implementing a simple binary search tree capable of storing numbers. The class should have member functions:
void insert(double x)
bool search(double x)
void inorder(vector <double> &v)

The insert function should not use recursion directly or indirectly. The search function should should work by calling a private recursion member function:
bool search(double x, BtreeNode *t)

The inorder function is passed an initially empty vector v, it fills v with the inorder list of numbers stored in the binary search tree. Finally i have to demonstrate the operation of the class using suitable driver program.

Is This A Good Question/Topic? 0
  • +

Replies To: Binary Search Tree

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Binary Search Tree

Posted 19 April 2010 - 03:45 AM

Have a read here:
http://en.wikipedia...._tree#Insertion
Was This Post Helpful? 0
  • +
  • -

#3 Jmaurice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-October 09

Re: Binary Search Tree

Posted 19 April 2010 - 06:55 PM

need help on inserting a binary tree without using recursion.. any tips
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3105
  • View blog
  • Posts: 19,144
  • Joined: 14-September 07

Re: Binary Search Tree

Posted 19 April 2010 - 07:04 PM

Duplicate threads merged. Please do not create multiple threads on the same problem.
Was This Post Helpful? 0
  • +
  • -

#5 Jmaurice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-October 09

Re: Binary Search Tree

Posted 20 April 2010 - 12:05 PM

Having a problem with the insert function to my binary tree.


Binary *temp= search(x);

if (temp == NULL)
{
temp= new Binary(x);
}
Was This Post Helpful? 0
  • +
  • -

#6 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3105
  • View blog
  • Posts: 19,144
  • Joined: 14-September 07

Re: Binary Search Tree

Posted 20 April 2010 - 12:27 PM

Merged again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1