All pastes #383634 Raw Edit

AlphaBETAtiCAL SoRT

public java v1 · immutable
·published 2007-03-06 14:53 UTC
rendered paste body
/** * @(#)testArrayList.java * * * @author Michael Cecconet * @version 1.00 2007/3/5 */import java.util.Arrays;import java.util.ArrayList;import java.lang.String;public class AlphabeticalSort {    static ArrayList<student> studentTracker = new ArrayList<student>();        public static void alphaSort(){    	char[] name1, name2;     	student placeHolder;   	    	student[] tempArray = new student[studentTracker.size()];    	    	for(int i=0;i<studentTracker.size();i++){    		tempArray[i] = studentTracker.get(i);    		//tempArray[i].displayInfo();    		    	}    	for (int i=0;i<tempArray.length-1;i++){        				    		name1 =tempArray[i].showLastName().toUpperCase().toCharArray();    		name2 =tempArray[i+1].showLastName().toUpperCase().toCharArray();    		    		    		for (int j=0;j<name1.length;j++){    			if ((int) name1[j] < (int)name2[j]){     			// Convert All to Upper then Compare ASCII values, Flipping Values Individually     			// By Repeating the sorting process for the upper bounds of the array.    			//System.out.println((int)'A');            	//System.out.println((char)65);            		    			} else{    				placeHolder=tempArray[i+1];    				tempArray[i+1]=tempArray[i];    				tempArray[i]=placeHolder;    				break;    			}    			   			    		}  		}				for (int k=0;k<tempArray.length;k++){			tempArray[k].displayInfo();		}		    }        public static void main(String args[]) {    	student tempReader;    	studentTracker.add(0,new student("HURR","BOTCH",66622666));    	studentTracker.add(1,new student("Cecconet", "Michael", 12943413));    	studentTracker.add(2,new student("Tennocec", "Leahcim", 31434921));    	studentTracker.add(3,new student("Simon", "Joshua", 23443413));    	studentTracker.add(4,new student("Defilipis", "Joe", 24523417));    	studentTracker.add(5,new student("Caia", "Gaspare", 32424123));    	studentTracker.add(6,new student("Test", "Test", 22222222));    	studentTracker.add(7,new student("Kitty", "Hello", 24234234));    	studentTracker.add(8,new student("Rocketfingers", "Johnny", 32424123));    	studentTracker.add(9,new student("Salad", "Tasty", 24324243));    	studentTracker.add(10,new student("Seafood", "Fresh", 86846354));    	studentTracker.add(11,new student("Pasta", "Steaming", 34324676));    	    	alphaSort();    	    	for(int i=0;i<studentTracker.size();i++){    		tempReader = studentTracker.get(i);    		tempReader.displayAll();    	}    }        }