Advertisement
Aldin-SXR

resize()

Mar 5th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.36 KB | None | 0 0
  1. /* Create a new internal array with a given capacity */
  2. @SuppressWarnings("unchecked")
  3. public void resize(int capacity) {
  4.     Item[] copy = (Item[]) new Object[capacity];    // 1
  5.     for (int i = 0; i < length; i++) {              // 2
  6.         copy[i] = q[(i + head) % q.length];         // 2
  7.     }                                               // 2
  8.     head = 0;                                       // 3
  9.     tail = length;                                  // 3
  10.     q = copy;                                       // 4
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement