// Michael Tartaglia
// 05 February 2002
// This program sorts an array's numbers into ascending order

import java.awt.Graphics;
import java.applet.Applet;

public class SelectionSort extends Applet {
   int a[] = {55,2,6,45,8,10,12,89,68,37};

   public void paint(Graphics g)
   {
      g.drawString("SELECTION SORTING",25,25);
      print(g, "Data items in original order: ",a,25,45);
      sort();
      print(g, "Data items in ascending order: ",a,25,75);
   }

   public void sort()
	// INPUT: none
	// FUNCTION: sorts global array "a" via bubble sort
   {
      int temp;
      for (int i = 0; i < a.length; ++i)
      {
         for (int j = i+1; j < a.length; ++j)
			{
            if (a[j] < a[i])
            {
					temp = a[i];
					a[i] = a[j];
					a[j] = temp;
				}
			}
      }
   }

   public void print(Graphics g, String head, int b[], int x, int y)
	// INPUT: graphics package, string to print, array to print, and x and y
	//			 coordinates at which to start
   {
      g.drawString(head,x,y);
      x+=15;
      y+=15;

      for (int i = 0; i < b.length; ++i)
      {	// PRINT ELEMENTS OF ARRAY
         g.drawString(String.valueOf(b[i]),x,y);
			x+=20;
      }
   }

}
