...

View Full Version : selection sort and insertion sort methods? - java



courtney2012
03-24-2012, 01:20 AM
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;
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum