/* * SortTest.java * * Created on November 25, 2004, 5:12 PM */ /** * * @author levenick */ import java.awt.*; public class SortTest extends java.applet.Applet { MyIntArrayList theList; MyIntArrayList sorted; /** Initializes the applet SortTest */ public void init() { initComponents(); testBubbleSort(); testInsertionSort(); } public void initList() { theList.addElement(8); theList.addElement(3); theList.addElement(2); theList.addElement(1); theList.addElement(4); } private void testBubbleSort() { theList = new MyIntArrayList(); initList(); System.out.println("before bubblesorting, it's:" + theList); bubbleSort(); System.out.println("after bubblesorting, it's:" + theList); } private void testInsertionSort() { theList = new MyIntArrayList(); initList(); System.out.println("before insertionsorting, it's:" + theList); insertionSort(); System.out.println("after insertionsorting, it's:" + theList); } public void bubbleSort() { for (int pass=0; pass theList.elementAt(look+1)) swap(look, look+1); } } } public void insertionSort() { //create an empty list, called sorted sorted = new MyIntArrayList(); //for each element of unsorted for (int nextI=0; nextI= all of them) return sorted.length(); } public void inPlaceInsertionSort() { for (int here=0; here