public static void main(String[] args) { AmortizedPQueue<Integer> queue = new AmortizedPQueue<Integer>(); queue = queue.plus(1).minus().minus().plus(2).plus(3).plus(4).plus(5).minus().plus(6).plus(7); PQueue<Integer> original = queue; System.out.println(" \t" + queue.front + " " + queue.back); while(queue.size() > 0) { int i = queue.peek(); queue = queue.minus(); System.out.println(i + " <- \t" + queue.front + " " + queue.back); } System.out.println(original); } }
public static void main(String[] args) { AmortizedPQueue<Integer> queue = new AmortizedPQueue<Integer>(); queue = queue.plus(1).minus().minus().plus(2).plus(3).plus(4).plus(5).minus().plus(6).plus(7); PQueue<Integer> original = queue; System.out.println(" \t" + queue.front + " " + queue.back); while(queue.size() > 0) { int i = queue.peek(); queue = queue.minus(); System.out.println(i + " <- \t" + queue.front + " " + queue.back); } System.out.println(original); } }
public AmortizedPQueue<E> minus() { if (size() == 0) { return this; } int fsize = front.size(); if (fsize == 0) { //If there's nothing on front, dump back onto front //(as stacks, this goes in reverse like we want) //and take one off. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()).minus(); } else if (fsize == 1) { //If there's one element on front, dump back onto front, //but now we've already removed the head. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()); } else { //If there's more than one on front, we pop one off. return new AmortizedPQueue<E>(front.minus(0), back); } }
public AmortizedPQueue<E> minus() { if (size() == 0) { return this; } int fsize = front.size(); if (fsize == 0) { //If there's nothing on front, dump back onto front //(as stacks, this goes in reverse like we want) //and take one off. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()).minus(); } else if (fsize == 1) { //If there's one element on front, dump back onto front, //but now we've already removed the head. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()); } else { //If there's more than one on front, we pop one off. return new AmortizedPQueue<E>(front.minus(0), back); } }
public static void main(String[] args) { AmortizedPQueue<Integer> queue = new AmortizedPQueue<Integer>(); queue = queue.plus(1).minus().minus().plus(2).plus(3).plus(4).plus(5).minus().plus(6).plus(7); PQueue<Integer> original = queue; System.out.println(" \t" + queue.front + " " + queue.back); while(queue.size() > 0) { int i = queue.peek(); queue = queue.minus(); System.out.println(i + " <- \t" + queue.front + " " + queue.back); } System.out.println(original); } }
public static void main(String[] args) { AmortizedPQueue<Integer> queue = new AmortizedPQueue<Integer>(); queue = queue.plus(1).minus().minus().plus(2).plus(3).plus(4).plus(5).minus().plus(6).plus(7); PQueue<Integer> original = queue; System.out.println(" \t" + queue.front + " " + queue.back); while (queue.size() > 0) { int i = queue.peek(); queue = queue.minus(); System.out.println(i + " <- \t" + queue.front + " " + queue.back); } System.out.println(original); }
public AmortizedPQueue<E> minus() { if (size() == 0) { return this; } int fsize = front.size(); if (fsize == 0) { //If there's nothing on front, dump back onto front //(as stacks, this goes in reverse like we want) //and take one off. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()).minus(); } else if (fsize == 1) { //If there's one element on front, dump back onto front, //but now we've already removed the head. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()); } else { //If there's more than one on front, we pop one off. return new AmortizedPQueue<E>(front.minus(0), back); } }
public AmortizedPQueue<E> minus() { if (size() == 0) return this; int fsize = front.size(); if (fsize == 0) { //If there's nothing on front, dump back onto front //(as stacks, this goes in reverse like we want) //and take one off. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()).minus(); } else if (fsize == 1) { //If there's one element on front, dump back onto front, //but now we've already removed the head. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()); } else { //If there's more than one on front, we pop one off. return new AmortizedPQueue<E>(front.minus(0), back); } }