Guest User

Untitled

a guest
Mar 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. Queue<Integer> q = new Queue<Integer>();
  2.  
  3. public class MyQueue<T extends Tree> implements Queue<T> {
  4. public T element() {
  5. ... your code to return an element goes here ...
  6. }
  7.  
  8. public boolean offer(T element) {
  9. ... your code to accept a submission offer goes here ...
  10. }
  11.  
  12. ... etc ...
  13. }
  14.  
  15. new Queue<Tree>() {
  16. public Tree element() {
  17. ...
  18. };
  19.  
  20. public boolean offer(Tree element) {
  21. ...
  22. };
  23. ...
  24. };
  25.  
  26. Queue<Integer> q = new LinkedList<Integer>();
  27.  
  28. Queue<Integer> q = new ArrayDeque<Integer>();
  29.  
  30. Queue<String> qe=new LinkedList<String>();
  31.  
  32. qe.add("b");
  33. qe.add("a");
  34. qe.add("c");
  35.  
  36. Queue linkedList = new LinkedList();
  37.  
  38. java.util.Queue<String> queue = new LinkedList<>();
  39. queue.offer("Hello");
  40. queue.offer("StackOverFlow");
  41. queue.offer("User");
  42.  
  43. System.out.println(queue.peek());
  44.  
  45. while (queue.size() > 0){
  46. System.out.println(queue.remove() + " ");
  47. }
  48. //Since Queue is empty now so this will return NULL
  49. System.out.println(queue.peek());
  50.  
  51. Hello
  52. Hello
  53. StackOverFlow
  54. User
  55. null
  56.  
  57. Queue<Integer> Q = new LinkedList<>();
  58.  
  59. Queue<Integer> Q = new ArrayDeque<>();
  60.  
  61. import java.util.LinkedList;
  62. import java.util.Queue;
  63.  
  64. public class QueueExample {
  65.  
  66. public static void main (String[] args) {
  67. Queue que = new LinkedList();
  68. que.add("first");
  69. que.offer("second");
  70. que.offer("third");
  71. System.out.println("Queue Print:: " + que);
  72.  
  73. String head = que.element();
  74. System.out.println("Head element:: " + head);
  75.  
  76. String element1 = que.poll();
  77. System.out.println("Removed Element:: " + element1);
  78.  
  79. System.out.println("Queue Print after poll:: " + que);
  80. String element2 = que.remove();
  81. System.out.println("Removed Element:: " + element2);
  82.  
  83. System.out.println("Queue Print after remove:: " + que);
  84. }
  85. }
  86.  
  87. Queue<Integer> Q = new LinkedList<Integer>();
Add Comment
Please, Sign In to add comment