/*	
	Mr. Bui
	10/4/06
	This program sorts the integer array using the bubble sort algorithm
*/

public class BubbleSort
{
	public static void main(String [] args)
	{
		int [] intArray = { 1, 2, 3, 4, 5, 1, 6, 42, 4, 6 ,3, 4, 2, 6, 7, 
			6, 4, 63, 12, 4, 7, 4, 2, 1, 3, 5, 7, 8, 7, 32, 56, 5, 35, 10 }; 
			
		int front = 0; 	// stores the index of the current front/top of the array
	
		int pos = 0;	//stores the index of the current position in the array
			
		//Create a for loop that uses "front" to iterate from 0 (zero) to the end of the array
		for (front = 0; front < intArray.length; front++)
		{
		
			//Create a nested for loop that uses "pos" to iterate from the end of the array down to "front"
			for (pos = intArray.length-1; pos > front; pos--)
			{
				//check to see if the element at "pos" is less than the adjacent element
				if (intArray[pos] < intArray[pos-1])
				{
					//swap the elements if the "pos" element is smaller
					int tmp = intArray[pos];
					intArray[pos] = intArray[pos-1];
					intArray[pos-1] = tmp;
				}
			}
		}
		
		//print out the entire array
		for(int i = 0; i < intArray.length; i++)
		{
			System.out.println(intArray[i]);
		}
	}
}