[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

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

0
jmkotman
Asked:
jmkotman
  • 2
2 Solutions
 
JimBrandleyCommented:
Can you please explain what you are trying to do here?

            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
            }
 
If you are looking for "Microsoft", what is the purpose of concatenating some characters from "TransUser" into another string?

Jim
0
 
JimBrandleyCommented:
Two more points:
1. Array.BinarySearch works on an ordered array only.
2. You say you have the information stored in a BST - not sure what you mean by that. Sounds like Binary (something) Tree. The data shows a name, some number, and links to the left child and right child. However, you are passing a multi-dimensional string array into your method.

We need more details about how you are storing the data before we can think about searching the contents.

Jim
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now