Results 1 to 2 of 2
  1. #1
    JavaNewb26 is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default Reading in a file, carrying out linear search, then sorting before Binary search

    hey guys I'm having some trouble with my code, the synopsis of the project is in the title but basically we have to read in a text file as an array, carry out a linear search, sort the output then carry out a binary search. I attached my code below, you'll notice I have two read methods, that section of the code was given to us in class, I'm assuming that the first one has to go because it has nothing to do with arrays. The professor wants us to run everything through main at the end, but Im not sure how to write the run method, also, the swap method at the end of shuffle() was also given to us, I know that code wont work for strings, how do I modify it so it does? Thanks in advance guys, sorry if I'm asking too many questions I'm just really lost here.


    import java.io.FileInputStream;

    import java.io.FileNotFoundException;

    import java.util.Scanner;

    public class HW4 {
    private Scanner in;
    private String[] theNames;

    public HW4(String fileName) throws FileNotFoundException {

    FileInputStream file = new FileInputStream(fileName);
    in = new Scanner(file);
    theNames = new String[10];

    }// constructor

    //Read the file
    private void read () {

    int count = 0;
    read(count);
    in.close();
    }//read()

    //Read file into array theNames

    private void read(int count) {

    theNames[count++] = in.nextLine();

    }//read()

    public void shuffle() {
    for (int index = 0; index < a.length; ++index) {
    int randomIndex = prng.nexInt(a.length);
    swap(index, randomIndex);
    }// for
    }// shuffle()

    //Linear searches for madre and padre





    //end linear searches

    //display sorted

    void display sorted (collection <string> lines) {

    TreeSet <string> =
    new TreeSet (lines);
    for (string s.t)
    system.out.println(s);

    }// display sorted()



    //Binary search for madre and padre





    //end binary search


    public static void main (String[] args) {

    }



    }//class HW4
    Last edited by JavaNewb26; 11-30-2012 at 07:06 PM. Reason: spacing was off

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Reading in a file, carrying out linear search, then sorting before Binary search

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. sequential search and binary search
    By qaseh in forum New To Java
    Replies: 2
    Last Post: 03-15-2012, 06:11 AM
  2. Please Help- Binary vs Linear search
    By johnjacob in forum New To Java
    Replies: 2
    Last Post: 06-01-2011, 03:37 AM
  3. Urgent/Help with Binary Vs Linear Search
    By johnjacob in forum New To Java
    Replies: 2
    Last Post: 06-01-2011, 02:17 AM
  4. Linear Search
    By Teclis in forum New To Java
    Replies: 19
    Last Post: 04-20-2011, 05:28 AM
  5. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 01:42 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
  •