Results 1 to 3 of 3
  1. #1
    Javanoobs is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default how to read list of name from text file into a binary search tree?

    As the title, how to read data from text file and load into a BST? suppose text file have name and phone number which name and phone number is a string, so when function invoked should read data from text file and load into a BST

    Java Code:
     public void readDataFile()     // read data from text fiel and load into BST
        {
         String fileName = "phonebook.txt";  // name of thr file
         Scanner fromFile = null;
            try{
                fromFile = new Scanner(new File(fileName));    // read from file phonebook.txt
            }
            catch(FileNotFoundException e)
      {
                System.out.println("Error : " +e);
                System.out.println("Unable to open file " + fileName);
            }
        DataFile tree = new DataFile();
         while (fromFile.hasNextLine())
         {
             String line = fromFile.nextLine();   // reads each line from the text file and stores it in line.
             tree.add(line);    // please help me this part
             
         }
         fromFile.close();
     }
    having problem with this,
    Java Code:
    tree.add(line)
    is the "add" suppose a function? or have any standard library command to replace it?

  2. #2
    Javanoobs is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default

    am i posting on the wrong section? or no one seems to know how to correct it?

  3. #3
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default

    this should help you, i guess you don't understand what a binary search tree is?

    Java binary tree code

Similar Threads

  1. Replies: 0
    Last Post: 04-04-2010, 07:40 AM
  2. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 01:42 AM
  3. Binary Search Tree
    By anmadie in forum New To Java
    Replies: 5
    Last Post: 11-17-2009, 02:39 AM
  4. Binary Search Tree
    By Goo in forum New To Java
    Replies: 0
    Last Post: 03-06-2009, 04:46 PM
  5. Binary Search Tree
    By michael_mke in forum New To Java
    Replies: 3
    Last Post: 12-04-2008, 02:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •