/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //Copyright Standish, Willey, and Suchenek //All rights reserved package split; /** * * @author suchenek */ public class QUEUE3 { List front; List rear; // points to the last element public void enqueue(E x) { cnt.incr(); List temp = new List(); temp.head = x; temp.tail = null; if(rear==null) { front = temp; rear = temp; } else { rear.tail = temp; rear = temp; //rear = rear.tail; } } public E dequeue() { cnt.incr(); if (rear == null) return null; // queue is empty E toReturn = front.head; front = front.tail; if(front == null) rear = null; // dequeued the only element return toReturn; } public Boolean isEmpty() { return front == rear; } public void dump() { List i = front; System.out.print("Dump:"); while (i!=null) { System.out.print(i.head + " "); i = i.tail; } System.out.println(" End Dump"); } public QUEUE3 cloneAbstract() // Deep clone { QUEUE3 toReturn = new QUEUE3(); for (List p = front; p !=null; p = p.tail) { toReturn.enqueue(p.head); } return toReturn; } public QUEUE3 clone() // Deep clone { QUEUE3 toReturn = new QUEUE3(); for (List p = front; p != null; p = p.tail) { List temp = new List (); temp.head = p.head; temp.tail = null; if (toReturn.rear == null) { toReturn.front = temp; toReturn.rear = temp; } else { toReturn.rear.tail = temp; toReturn.rear = temp; } } return toReturn; } }