I'm trying to figure out how to add an element to an array of integers, but the tricky part is that I have to slide the elements to the right of it over by one place.
For example:
Start array: {1, 2, 3, 4, 5, 6, 7}
Adding 10 to index of 3
End result: {1, 2, 3, 10, 4, 5, 6, 7}
This what I have so far. Thanks so much.
//slide all elements over
for(int i=index; i<values; i++){
int holder=array[i];//holds value that is going to be replaced
//are overriding values in i+1, need to save
array[i+1]=holder;
}
array[index]=element;