# Thread: ABt Binary Search Trees

1. ## ABt Binary Search Trees

Write a program that will allow randomized 0..100 numbers and the 15 generated numbers will serve as the input to ur binary search tree. The program should then print out the contents of your BST using preorder, inorder, and postorder traversals, store the result in the text file ( bst.txt)Recall the convention to place any duplicate number in the left subtree of that letter.

So far ive only done the randomize process... help me do the other parts...please any idea will help... or if you give the code much better,,,

Thx ...

Code:
```#include<stdlib.h>
#include<iostream.h>
#include<conio.h>

int main()

{

clrscr();

srand((unsigned)time(0));
int random_integer = rand();

for(int index=0; index<15; index++) {
random_integer = (rand()%100)+1;
cout << random_integer << endl;
}
getch();
}``` 2. >Write a program that will allow randomized 0..100 numbers
> random_integer = (rand()%100)+1;
That gives you numbers from 1..100. 3. How can I traverse those 15 random numbers?? 4. use an array
Code:
```int random_integer
for(int index=0; index<14; index++) {
random_integer[i] = (rand()%100)+1;
cout << random_integer[i] << endl;
}
for(int index=14; index>0; index--) {// check through in reverse order
cout << random_integer[i] << endl;
}```
they are the only ways you can transverse through the list(?), though you can point to a specific array element by using random_interger or whatever number element you want to look at.

also this isn't a binary search tree that you are asking for, however you have written "this will be the input for your search tree" so I assume that you already have a separate search tree?. http://en.wikipedia.org/wiki/Binary_search_tree 5. Originally Posted by ging ging How can I traverse those 15 random numbers??
You need to build the binary search tree containing those random numbers.
You could use an array with the same indexing scheme as a heap, but the normal way to do it is to build a tree out of separately allocated nodes. Do you know how to build a linked-list? Building a tree is just a step up from there.

Now you've been told that your code does not generate numbers in the correct range (does not include zero). Have you figured out how to fix that yet? Popular pages Recent additions 