Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Queue<Integer> q = new Queue<Integer>();
- public class MyQueue<T extends Tree> implements Queue<T> {
- public T element() {
- ... your code to return an element goes here ...
- }
- public boolean offer(T element) {
- ... your code to accept a submission offer goes here ...
- }
- ... etc ...
- }
- new Queue<Tree>() {
- public Tree element() {
- ...
- };
- public boolean offer(Tree element) {
- ...
- };
- ...
- };
- Queue<Integer> q = new LinkedList<Integer>();
- Queue<Integer> q = new ArrayDeque<Integer>();
- Queue<String> qe=new LinkedList<String>();
- qe.add("b");
- qe.add("a");
- qe.add("c");
- Queue linkedList = new LinkedList();
- java.util.Queue<String> queue = new LinkedList<>();
- queue.offer("Hello");
- queue.offer("StackOverFlow");
- queue.offer("User");
- System.out.println(queue.peek());
- while (queue.size() > 0){
- System.out.println(queue.remove() + " ");
- }
- //Since Queue is empty now so this will return NULL
- System.out.println(queue.peek());
- Hello
- Hello
- StackOverFlow
- User
- null
- Queue<Integer> Q = new LinkedList<>();
- Queue<Integer> Q = new ArrayDeque<>();
- import java.util.LinkedList;
- import java.util.Queue;
- public class QueueExample {
- public static void main (String[] args) {
- Queue que = new LinkedList();
- que.add("first");
- que.offer("second");
- que.offer("third");
- System.out.println("Queue Print:: " + que);
- String head = que.element();
- System.out.println("Head element:: " + head);
- String element1 = que.poll();
- System.out.println("Removed Element:: " + element1);
- System.out.println("Queue Print after poll:: " + que);
- String element2 = que.remove();
- System.out.println("Removed Element:: " + element2);
- System.out.println("Queue Print after remove:: " + que);
- }
- }
- Queue<Integer> Q = new LinkedList<Integer>();
Add Comment
Please, Sign In to add comment