Showing posts with label Queue Implementation using java. Show all posts
Showing posts with label Queue Implementation using java. Show all posts

Tuesday, August 21, 2012

Queue Operations Using LinkedList in Java



import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;


public class QueueOperations {

public static void main(String args[]){

Queue que=new LinkedList();

//Insert elements into Queue
que.offer(12);
que.offer(25);
que.offer(75);
que.offer(9);

System.out.println("Queue"+que);

//Queue Operations
System.out.println("Queue Peek the elmenet  "+que.peek());
System.out.println("Queue Remove Element "+que.poll());

System.out.println("isEmpty :?"+que.isEmpty());
}
}

Output:
Queue[12, 25, 75, 9]
Queue Peek the elmenet  12
Queue Remove Element 12
isEmpty :?false