/* * Split.java * * Created on March 17, 2008, 1:20 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package split; /** * * @author suchenek */ public class Split { public static void main(String[] args) { // TODO code application logic here int[] Array; int N, K = 6; // para for the number of insertions cnt.clr(); //counts enqueue's cnt2.clr(); //counts cost of Stretch cnt3.clr(); //counts dequeue's cnt4.clr(); //counts cost of Shrink // for (K = 1; K<=100; K++) { N = K*15; Array = new int[N]; for (int i = 0; i < N; i++) Array[i] = i + 1; Test(Array); for (int i = 0; i < N; i++) System.out.print(Array[i] + " "); System.out.println(" End array"); // System.out.print("T(" + N +")"); // cnt.out(" = "); // System.out.println(" " + (N) + " = N"); System.out.print("Avg. cost of Stretch per enque S(" + N +")"); System.out.println(" = " + (1.0*cnt2.get()/cnt.get())); System.out.print("Avg. cost of Shrink per deque T(" + N +")"); System.out.println(" = " + (1.0*cnt4.get()/cnt3.get())); } } public static void Test(int[] A) { int n = A.length; // int lastEnq = 0, lastDeq = 0; QUEUE Q = new QUEUE(); Q.showAll(); for (int m = 0; m*15 < n; m++) { for (int i = 0; i < 15; i++) { Q.enqueue(A[i + m*15]); A[i + m*15] = 0; // lastEnq = i + m*15; } // Q.dump(); // System.out.println("A Size of Q is " + Q.Length()); for (int i = 0; i < 13; i++) { A[i + m*13]=Q.dequeue(); // System.out.print("A[i]=Q.deq A[" + i + "]=" + A[i] + " "); // lastDeq = i + m*11; } // System.out.println(); // System.out.println("B Size of Q is " + Q.Length()); } // Q.enqueue(999); // for (int i = 0; i < 9; i++) // { // A[i + lastDeq]=Q.dequeue(); //// System.out.print("A[i]=Q.deq A[" + i + "]=" + A[i] + " "); // } Q.dump(); } }