Puzzle DC30


Insert a value at location N, move elements up to make room

[E-7] Write function that inserts a value at index N in an array. First it moves all elements above index N upward. The last element is discarded. If index N does not exist, do nothing to the array. Return 1 if the insertion was performed, 0 if not.

   0    1    2    3    4    5    6    7    8    9
  10   11   12   13   14
value place: 99 0
Success

  99    0    1    2    3    4    5    6    7    8
   9   10   11   12   13
value place: 77 9
Success

  99    0    1    2    3    4    5    6    7   77
   8    9   10   11   12
value place:


Answer         Next Page         Previous Page Home