Files
GTSchoolShit/CS1322/p5/BubbleSort.java
2025-06-07 01:59:34 -04:00

79 lines
1.9 KiB
Java

/**
* <PRE>
* BubbleSort.java
*
* Revisions: 1.0 Nov. 04, 2002
* Created the BubbleSort class
* 1.1 Nov. 07, 2002
* Finished, Compiled, Commented
*
* </PRE>
*
* Collaboration Statement:
* I worked on the homework assignment alone, using only
* course materials.
*
* Created with JCreatorLE, some indents are off when viewed through notepad
* or EMACS
*
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
* @version Version 1.1, Nov. 07, 2002
*/
public class BubbleSort extends AbstractSort{
////////////////
//Constructors//
////////////////
/**
*Constructor for BubbleSort
*@param arrayWrap, the array to be sorted
*/
public BubbleSort(ArrayWrapper arrayWrap){
super(arrayWrap);
}
///////////
//Methods//
///////////
/**
*Sort the Array
*/
public void doSort(){
for(int i=0; i<arrayWrap.length()-1; i++){
for(int z=0; z<arrayWrap.length()-1-i; z++){
if(arrayWrap.get(z+1).compareTo(arrayWrap.get(z))<0){
arrayWrap.swap(z+1,z);
}
}
}
}//end doSort()
/*****************************************************/
/**
* Debugging main for class BubbleSort.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
ArrayWrapper aw = new ArrayWrapper(ArrayWrapper.getRandomIntegerArray(40));
BubbleSort bs = new BubbleSort(aw);
for(int i=0;i<aw.length();i++){
System.out.println(aw.get(i));
}
bs.doSort();
System.out.println("\n/****Testing Now****/\n");
for(int i=0;i<aw.length();i++){
System.out.println(aw.get(i));
}
}// end of main(String[] args)
}// end of class BubbleSort