// // Queue: linked list based public class Queue { private ListNode front; private ListNode rear; public Queue() { front = null; rear = null; } public boolean isEmpty() { return (front==null && rear==null); } public void enqueue(String item) { ListNode temp = new ListNode(item, null); if(isEmpty()) // empty { front = temp; rear = temp; } else // at leat one node { rear.setLink(temp); rear = temp; } } public String dequeue() { String str = " "; if(isEmpty()) System.out.println("Error! Empty list."); else { str = front.getData(); if(front == rear) // only one node { front = null; rear = null; } else // at least two nodes front = front.getLink(); System.out.println("\n" + str + " was dequeued."); } return str; } public void Print() { ListNode temp = front; System.out.print("The queue is: "); while(temp!=null) { System.out.print(temp.getData() + " "); temp = temp.getLink(); } System.out.println("\n"); } } /* public static void main(String[] args) { Queue2 myQueue = new Queue2(); myQueue.enqueue("Jon"); myQueue.enqueue("Smith"); myQueue.enqueue("Denise"); myQueue.enqueue("Vic"); myQueue.Print(); myQueue.dequeue(); myQueue.Print(); } } */