/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package bubblesort; /** * * @author suchenek */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { int[] Array; int N; for (N = 2; N<=100; N++) { System.out.println("********* " + N + " *********"); Array = new int[N]; for (int i = 0; i < N; i++) Array[i] = (int)(Math.sqrt(97)*(13*i + 1)*(19*i + 2)+i - 17)%1000; // for (int i = 0; i < N; i++) // Array[i] = -i; for (int i = 0; i < N; i++) System.out.print(Array[i] + " "); System.out.println(); cnt.clr(); //counts running time while sorting of both arrays System.out.println("Sorting Array[" + N + "]"); SelectionSort(Array); for (int i = 0; i < N; i++) System.out.print(Array[i] + " "); System.out.println(); System.out.print("T(" + N +")"); cnt.out(" = "); System.out.println(); // System.out.println("N*(N-1)/2 = " + (N*(N-1)/2) ); System.out.println("(N*N + 5*N)/2 - 3 = " + ((N*N + 5*N)/2 - 3) ); } } // This is a copy of the code from your textbook with my additions. // For classroom use in CSC 311, only. // Do not copy it for any other use. // Do not share it with any one. static void SelectionSort (int A[]) { int maxPosition, temp, i, j; int c = 1; //my addition int d = 3; //my addition for (i = A.length - 1; i > 0; i--) { maxPosition = i; for (j = 0; j < i; j++) { if (A[j] > A[maxPosition]) maxPosition = j; cnt.incr(c); //my addition } temp = A[i]; A[i] = A[maxPosition]; A[maxPosition] = temp; cnt.incr(d); //my addition } } }