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

03-22-2012, 11:04 PM
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.

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++) {

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 ) {
word = in.readLine();
} catch( Exception e )
return list;

Old Pedant
03-22-2012, 11:43 PM
This is the JavaSCRIPT forum.

Your question is about JAVA.

About the only thing the two languages have in common are the letters J-A-V-A at the start of their names.

By the way: Google is your friend. Clearly this is homework, so try googling for how the two kinds of sorts work.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum