fork download
  1. package queue;
  2.  
  3. class Queue
  4. {
  5. private int maxSize;
  6. private long[] queArray;
  7. private int front;
  8. private int rear;
  9. private int nItems;
  10.  
  11. public Queue(int s)
  12. {
  13. maxSize = s;
  14. queArray = new long[maxSize];
  15. front = 0;
  16. rear = -1;
  17. nItems = 0;
  18. }
  19.  
  20. public void insert(long j)
  21. {
  22. if(rear == maxSize-1)
  23. rear = -1;
  24. queArray[++rear] = j;
  25. nItems++;
  26. }
  27.  
  28. public long remove()
  29. {
  30. long temp = queArray[front++];
  31. if(front == maxSize)
  32. front = 0;
  33. nItems--;
  34. return temp;
  35. }
  36.  
  37. public long peekFront()
  38. {
  39. return queArray[front];
  40. }
  41.  
  42. public boolean isEmpty()
  43. {
  44. return (nItems==0);
  45. }
  46.  
  47. public boolean isFull()
  48.  
  49. {
  50. return (nItems==maxSize);
  51. }
  52.  
  53. public int size()
  54. {
  55. return nItems;
  56. }
  57.  
  58. }
  59.  
  60. class QueueApp
  61. {
  62. public static void main(String[] args)
  63. {
  64. Queue theQueue = new Queue(5);
  65. theQueue.insert(10);
  66. theQueue.insert(20);
  67. theQueue.insert(30);
  68. theQueue.insert(40);
  69. theQueue.remove();
  70. theQueue.remove();
  71. theQueue.remove();
  72. theQueue.insert(50);
  73. theQueue.insert(60);
  74. theQueue.insert(70);
  75. theQueue.insert(80);
  76. while( !theQueue.isEmpty() )
  77. {
  78. long n = theQueue.remove();
  79. System.out.print(n);
  80. System.out.print(" ");
  81. }
  82. System.out.println("");
  83. }
  84. }
Runtime error #stdin #stdout #stderr 0.06s 974336KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: Could not find or load main class QueueApp