@@ -0,0 +1,1463 @@
+import java.util.LinkedList;%0Aimport java.util.NoSuchElementException;%0Aimport java.util.Queue;%0A%0Apublic class QueueClass %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09%0A%09%09Queue%3CString%3E myQueue = new LinkedList%3CString%3E(); %0A%0A%09%09// add elements in the queue using offer() - return true/false%0A%09%09myQueue.offer(%22Monday%22);%0A%09%09myQueue.offer(%22Thusday%22);%0A%09%09boolean flag = myQueue.offer(%22Wednesday%22);%0A%09%09%0A%09%09System.out.println(%22Wednesday inserted successfully? %22+flag);%0A%09%09%0A%09%09// add more elements using add() - throws IllegalStateException%0A%09%09try %7B%0A%09%09%09myQueue.add(%22Thursday%22);%0A%09%09%09myQueue.add(%22Friday%22);%0A%09%09%09myQueue.add(%22Weekend%22);%0A%09%09%7D catch (IllegalStateException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09%0A%09%09System.out.println(%22Pick the head of the queue: %22 + myQueue.peek());%0A%09%09%0A%09%09String head = null;%0A%09%09try %7B%0A%09%09%09// remove head - remove()%0A%09%09%09head = myQueue.remove();%0A%09%09%09System.out.print(%221) Push out %22 + head + %22 from the queue %22); %0A%09%09%09System.out.println(%22and the new head is now: %22+myQueue.element());%0A%09%09%7D catch (NoSuchElementException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09%0A%09%09// remove the head - poll()%0A%09%09head = myQueue.poll();%0A%09%09System.out.print(%222) Push out %22 + head + %22 from the queue%22);%0A%09%09System.out.println(%22and the new head is now: %22+myQueue.peek());%0A%09%09%0A%09%09// find out if the queue contains an object%0A%09%09System.out.println(%22Does the queue contain 'Weekend'? %22 + myQueue.contains(%22Weekend%22));%0A%09%09System.out.println(%22Does the queue contain 'Monday'? %22 + myQueue.contains(%22Monday%22));%0A%09%7D%0A%0A%7D

Add files via upload