Advertisement
Aldin-SXR

enqueue()

Mar 5th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.25 KB | None | 0 0
  1. /* Add a new item to the back of the queue */
  2. public void enqueue(Item item) {
  3.     if (q.length == length) {       // 1
  4.         resize(2 * q.length);       // 1
  5.     }                               // 1
  6.        
  7.     q[tail] = item;                 // 2
  8.     tail = (tail + 1) % q.length;   // 3
  9.     length++;                       // 4
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement