Java Queue Interface
The Queue interface basically orders the element in FIFO(First In First Out)manner.
Methods of Queue Interface :
- public boolean add(object);
- public boolean offer(object);
- public remove();
- public poll();
- public element();
- public peek();
PriorityQueue class:
The PriorityQueue class provides the facility of using queue. But it does not orders the elements in FIFO manner.
Example of PriorityQueue
Output:head:Amit
head:Amit
iterating the queue elements:
Amit
Jai
Karan
Vijay
Rahul
after removing two elements:
Karan
Rahul
Vijay
No comments:
Post a Comment