Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Location
    Canada
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    selection sort and insertion sort methods? - java

    I have been working on the code for an alpha sort file and have become stumped. I need to incorporate both an insertion sort & selection sort method into my code before it will run.

    I attached the file I have been working on and it runs on Bluej with Java JDK. I would apretiate if you could take a look at it. If you would prefer not to download my file I have posted my code that I have been working on below.

    I am not familiar with the structure of an insertion sort or a selection sort mothod. I also am not clear on the point in which these methods would need to be placed in the file.


    Code:
    import java.io.*;
    import java.util.*;

    public class Words
    {
    ArrayList<String> words;

    public Words()
    {
    words = getData("wordlist.txt");
    }

    public void displayWords()
    {
    for(int i=0; i<words.size(); i++) {
    System.out.println(words.get(i));
    }
    }

    public ArrayList<String> getData(String filename)
    {
    ArrayList<String> list = new ArrayList<String>();
    File myFile = new File(filename);
    if(myFile.exists() && myFile.length()>0) {
    try {
    BufferedReader in = new BufferedReader( new FileReader(myFile) );
    String word = in.readLine();
    while( word != null ) {
    list.add(word);
    word = in.readLine();
    }
    } catch( Exception e )
    {}
    }
    return list;
    }
    }
    Attached Files Attached Files


 

Posting Permissions

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