Binary Search Tree

Thread Solved

Join Date: Apr 2008
Posts: 15
Reputation: dimples09 is an unknown quantity at this point 
Solved Threads: 0
dimples09 dimples09 is offline Offline
Newbie Poster

Re: Binary Search Tree

 
0
  #11
Apr 22nd, 2008
I would like to say thanks for being patient with me cause Im new at this! This is what I have done and this comes out with two errors

public static void main(String[] args) throws IOException
{





try
{

BufferedReader reader = new BufferedReader( new FileReader("numbers.txt") );

String line = reader.readLine();

while ((line = reader.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line);

// count how many tokens inside st object
System.out.println("tokens count: " + st.countTokens());

while(st.hasMoreElements())
{

String token = st.nextElement().toString();
System.out.println("token = " + token);

}


// do your thing



line = reader.readLine();

}

}
catch(Exception ex)
{

ex.printStackTrace();

}
}
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 15
Reputation: dimples09 is an unknown quantity at this point 
Solved Threads: 0
dimples09 dimples09 is offline Offline
Newbie Poster

Re: Binary Search Tree

 
0
  #12
Apr 22nd, 2008
this is how my text file reads:
65 47 87 48 11 89 27 6 4 3 2 7 33 68 78 57 83 27 6 78 11 75 9 10 19 53 2
addElement
removeElement
removeMax
removeMin
findMax
findMin
find

ps the preOrder
PostOrder
inOrder are not working right so the professor is now takin them out. We also have a jss2 file within our folder
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 15
Reputation: dimples09 is an unknown quantity at this point 
Solved Threads: 0
dimples09 dimples09 is offline Offline
Newbie Poster

Re: Binary Search Tree

 
0
  #13
Apr 23rd, 2008
Hi I have been working out the kinks in my program and I have progressed a little more. Here is what I have:

import java.util.StringTokenizer;
import java.util.Scanner;
import jss2.*;
import java.io.*;




public class LinkedBSearch
{

public static void main(String[] args) throws IOException
{


Scanner fileScan;
String aNumber;






//create an empty Tree
LinkedBinarySearchTree<Integer> myBST = new LinkedBinarySearchTree<Integer> ();
System.out.println("I did not receive any help from anyone except for Mr. Willis and the assigned tutor");
System.out.println("Succesfully created nothing...an empty tree");



// create a Scanner object for reading a file
fileScan = new Scanner(new File("numbers.txt"));



try
{
//Create a new Scanner object which will read the data from the
// file passed in. To check if there are more line to read from it
// we check by calling the fileScan.next() method. We then
// read line one by one till all lines are read.


int aToken;
String tokenLine = fileScan.nextLine();

StringTokenizer st = new StringTokenizer(tokenLine);
System.out.println ("********* " + tokenLine);


while(st.hasMoreTokens())
{

aToken = Integer.parseInt (st.nextToken());
System.out.println ("$$$ " + aToken);
//add one element at a time to the tree.
if (!tokenLine.equals(""))
{
myBST.addElement(aToken);
}
else
{
System.out.println("\nCannot add empty data!");
}






}

// Print the tree.
System.out.println(myBST);


while (fileScan.hasNext())
{
String line = fileScan.next();
System.out.println(line);
}

}
catch (Exception e)
{
e.printStackTrace();
}
}
}

jGRASP exec: java LinkedBSearch

I did not receive any help from anyone except for Mr. Willis and the assigned tutor
Succesfully created nothing...an empty tree
********* 65 47 87 48 11 89 27 6 4 3 2 7 33 68 78 57 83 27 6 78 11 75 9 10 19 53 2
$$$ 65
$$$ 47
$$$ 87
$$$ 48
$$$ 11
$$$ 89
$$$ 27
$$$ 6
$$$ 4
$$$ 3
$$$ 2
$$$ 7
$$$ 33
$$$ 68
$$$ 78
$$$ 57
$$$ 83
$$$ 27
$$$ 6
$$$ 78
$$$ 11
$$$ 75
$$$ 9
$$$ 10
$$$ 19
$$$ 53
$$$ 2
65
47
11
6
4
3
2
2
7
6
9
10
27
11
19
33
27
48
57
53
87
68
78
75
83
78
89

addElement
removeElement
removeMax
removeMin
findMax
findMin
find

----jGRASP: operation complete.
Im reading the numbers and command from a txt file
This compiles without any error but what im trying to figure out is how do I add each node into the myBST. Also how to get the commands not to print out?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC