Link to home
Start Free TrialLog in
Avatar of jmkotman
jmkotmanFlag for United States of America

asked on

Find Item in BST

I have written a program which creates the BST that is attached.  All nodes have a left and right child pointer that points to the next node.  I am trying to write a method that will read in a string from a file and then search the BST for that string.  If it finds it it will write to the log file.  I have written the following code but it doesn't seem to search through the array.  Any ideas or ways to fix it?
microsoft        3989898989 02 03 
java             1357357357 05 12 
zipinfo          0490080000 04 28 
pizzahut         3789789789 20 07 
google           3333333333 06 08 
cnn              1444444444 21 09 
yahoo            2121212121 11 00 
ilounge          4040404040 18 00 
dictionary       0555555555 31 10 
expedia          1234543210 00 17 
un               3939393939 13 14 
limewire         1010101010 22 00 
quicken          4294967295 00 15 
verizon          2468246824 00 16 
secondlive       1888888888 25 26 
wikipedia        4242424242 00 19 
facebook         1616161616 00 29 
howstuffworks    0000000001 00 00 
xe               0123123123 00 00 
nytimes          1234554321 27 23 
barnesandnoble   1111111111 24 00 
kalamazoocity    2444666888 00 00 
oprah            2999999999 00 00 
amazon           2222222222 00 30 
radioshack       4294000000 00 00 
tripadvisor      0777777777 00 00 
 
 
public static void Query(ref StreamReader ReadUser,ref string TransUser, ref string[,] BSTHold)
        {
            string urlRead = "";
 
            for(int i = 2; i < 18; i++)
            {
                urlRead += TransUser[i].ToString(); //if i read in    microsoft, i want it to search the array for it
            }
 
            int index = Array.BinarySearch(BSTHold, 0, BSTHold.Length, urlRead);
 
            if (index > 0)
            {
                MessageBox.Show("Found {0}", urlRead);
            }
            else if (index == BSTHold.Length)
            {
                MessageBox.Show("{0} was not found", urlRead);
            }
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JimBrandley
JimBrandley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial