| 200 | } |
| 201 | |
| 202 | int array_pred_insert(ARRAY *a, int position, void *obj) |
| 203 | { |
| 204 | int idx; |
| 205 | |
| 206 | /* |
| 207 | * a->items[count - 1] should be the last valid item node |
| 208 | * position should: positioin >= 0 && position <= a->count - 1 |
| 209 | */ |
| 210 | if(position < 0 || position >= a->count) { |
| 211 | return -1; |
| 212 | } |
| 213 | |
| 214 | if(a->count >= a->capacity) { |
| 215 | array_grow(a, a->count + 1); |
| 216 | } |
| 217 | |
| 218 | /* NOTICE: the C's index begin with 0 |
| 219 | * when position == 0, just prepend one new node before the first node |
| 220 | * of the array |
| 221 | */ |
| 222 | for(idx = a->count; idx > position && idx > 0; idx--) { |
| 223 | /* if idx == 0 then we has arrived |
| 224 | * at the beginning of the array |
| 225 | */ |
| 226 | a->items[idx] = a->items[idx - 1]; |
| 227 | } |
| 228 | a->items[position] = obj; |
| 229 | a->count++; |
| 230 | return position; |
| 231 | } |
| 232 | |
| 233 | int array_succ_insert(ARRAY *a, int position, void *obj) |
| 234 | { |
no test coverage detected
searching dependent graphs…