All pastes #384531 Raw Edit

(FIN) Alpha Sort

public java v1 · immutable
·published 2007-03-07 03:47 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;    	String nam1,nam2;     	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 g=0;g<tempArray.length;g++){    	for (int i=0;i<tempArray.length-1;i++){//Two Student Compare     	       		nam1 =tempArray[i].showLastName().toLowerCase();    		nam2 =tempArray[i+1].showLastName().toLowerCase();    						    		name1 =nam1.toCharArray();    		name2 =nam2.toCharArray();    		//System.out.println(tempArray[i].showLastName()+", "+tempArray[i].showFirstName()+" comparing with "+tempArray[i+1].showLastName()+", "+tempArray[i+1].showFirstName() );    		    		if (nam1.toLowerCase().indexOf(nam2.toLowerCase() ) >= 0){// Check For the same last name, if true compares first names.    			//System.out.println(tempArray[i].showLastName()+", "+tempArray[i].showFirstName()+" has the same last name as "+tempArray[i+1].showLastName()+", "+tempArray[i+1].showFirstName() );    			nam1= tempArray[i].showFirstName().toLowerCase();    			nam2= tempArray[i+1].showFirstName().toLowerCase();    			name1 = nam1.toCharArray();    			name2 = nam2.toCharArray();    		}    			    					for (int j=0;j <= name1.length;j++){				if (name1[j] > name2[j]){					//System.out.println(tempArray[i].showLastName()+", "+tempArray[i].showFirstName()+" goes behind "+tempArray[i+1].showLastName()+", "+tempArray[i+1].showFirstName() );					placeHolder=tempArray[i];    				tempArray[i]=tempArray[i+1];    				tempArray[i+1]=placeHolder;    				break;					} else {					if (name1[j] < name2[j]){						//System.out.println(tempArray[i].showLastName()+", "+tempArray[i].showFirstName()+" is in proper position between "+tempArray[i+1].showLastName()+", "+tempArray[i+1].showFirstName() );						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("Cecconet","Michael",66622666));    	studentTracker.add(1,new student("Cecconet", "Dopelganger", 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();    	}*/    }        }    			// 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);