Advertisement
Aldin_SXR

dequeue()

Mar 4th, 2024
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. /* Removes an item from the front of the queue, and returns its data */
  2. public Data dequeue() {
  3.     if (isEmpty()) {                                                // 1
  4.         throw new NoSuchElementException("Queue is empty!");        // 1
  5.     }
  6.  
  7.     Data data = head.data;                                          // 2
  8.     head = head.next;                                               // 3
  9.     size--;                                                         // 4
  10.  
  11.     if (isEmpty()) {                                                // 5
  12.         tail = null;                                                // 5
  13.     }
  14.  
  15.     return data;                                                    // 6
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement