// The "Bubble" class.

import hsa.Console;

public class Bubble
{
    //This class provides a bubble sort for doubles.
    static Console c = new Console();
    
    void bubbleSort(double [] v, int n)
    //bubbleSort method receives an array of doubles and an integer telling howmany elements
    //and sorts those doubles into numberic order from smallest to largest.
    {
	int i, j = 0;// counters
	double temp = 0;//to hold a value temporarily
	for (i = n-1; i>=0; i--)//start at the end of the array and work downward
	{
	    for (j = 0; j<i; j++)//start at the beginning of the array and work upward
	    {
		if (v[j] > v[j+1])//check each pair to see if any exchange should take place
		{
		    //swap values if necessary
		    temp = v[j];
		    v[j] = v[j+1];
		    v[j+1] = temp;
		}
	    }
	}
	
    }
    
    public static void main (String[] args)
    {
	int i, number = 0;//number represents how many elements are to be entered
	double[] values ;// values is an array to hold the doubles to be sorted
	Bubble b = new Bubble();//a class member to call methods
	
	c.println("How many values?");
	number = c.readInt();//read in how many elements are to be entered
	values = new double[number];//start an array to hold the values
	    //values has its first entry in the 0th position and the last one in the 
	    //number-1 position
	c.println("Enter your numbers, one per line");
	
	for(i=0; i<number; i++)
	    values[i] = c.readDouble();//read and store the values
	    
	b.bubbleSort(values, number);//call the method that sorts the values
	
	c.println("The sorted values are ");//print the sorted values
	for(i=0; i<number; i++)
	c.println(values[i]);
	
	    
    } // main method
} // Bubble class

