/* * PriorityQueueTestL.java * SORTED INSERT LIST IMPLEMENTATION * Created on March 3, 2008, 3:41 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package priorityqueuetest; /** * * @author suchenek */ public class PriorityQueueTestL { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int[] Array; int N; for (N = 1; N<=100; 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 moves of keys while sorting Bcnt.clrAll(); //counts comparisons of keys while sorting PriorityQueueSort(Array); for (int i = 0; i < N; i++) System.out.print(Array[i] + " "); System.out.println(); // Tcomp(N) is the sorting "time" measured by the number of comparisons // of keys System.out.print("Tcomp(" + N +")"); Bcnt.out(" = "); System.out.print(" " + ( N*(N-1)/2) + " = N*(N-1)/2" + " "); // Tcall(N) is the sorting "time" measured by the number of calls System.out.print(" Tcall(" + N +")"); cnt.out(" = "); System.out.println(" " + (2*N + N*(N-1)/2) + " = 2*N + N*(N-1)/2"); } } public static void PriorityQueueSort(int[] A) { int n = A.length; PriorityQueueL PQ = new PriorityQueueL(); for (int i = 0; i < n; i++) PQ.insert(A[i]); // for (int i = n-1; i >= 0; i--) PQ.insert(A[i]); // System.out.println("A Size of PQ is " + PQ.Length()); for (int i = n-1; i >= 0; i--) A[i]=PQ.remove(); // for (int i = 0; i < n; i++) A[i]=PQ.remove(); // System.out.println("B Size of PQ is " + PQ.Length()); } }