(int capacity)
| 141 | |
| 142 | // 扩容方法,时间复杂度 O(n) |
| 143 | private void resize(int capacity) { |
| 144 | T[] newData = (T[]) new Object[capacity]; |
| 145 | |
| 146 | for (int i = 0; i < size; i++) { |
| 147 | newData[i] = data[i]; |
| 148 | } |
| 149 | data = newData; |
| 150 | } |
| 151 | |
| 152 | private void checkIndex(int index) { |
| 153 | if (index < 0 || index >= size) { |