1 /* |
1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
290 } |
293 } |
291 } |
294 } |
292 ShouldNotReachHere(); |
295 ShouldNotReachHere(); |
293 } |
296 } |
294 |
297 |
|
298 // The order is preserved. |
295 void remove_at(int index) { |
299 void remove_at(int index) { |
296 assert(0 <= index && index < _len, "illegal index"); |
300 assert(0 <= index && index < _len, "illegal index"); |
297 for (int j = index + 1; j < _len; j++) _data[j-1] = _data[j]; |
301 for (int j = index + 1; j < _len; j++) _data[j-1] = _data[j]; |
298 _len--; |
302 _len--; |
|
303 } |
|
304 |
|
305 // The order is changed. |
|
306 void delete_at(int index) { |
|
307 assert(0 <= index && index < _len, "illegal index"); |
|
308 if (index < --_len) { |
|
309 // Replace removed element with last one. |
|
310 _data[index] = _data[_len]; |
|
311 } |
299 } |
312 } |
300 |
313 |
301 // inserts the given element before the element at index i |
314 // inserts the given element before the element at index i |
302 void insert_before(const int idx, const E& elem) { |
315 void insert_before(const int idx, const E& elem) { |
303 check_nesting(); |
316 check_nesting(); |