Insert Value in Array using FOR?

May 28, 2014 at 8:48pm
Hey i cant insert succesfully values in my array without losing the last value.

I need it to work this way
e.g;
Array:
1)1
2)2
3)3
4)5

------
inserting value: 2 in pos 3
1)1
2)2
3)3
4)2
5)5

...
im using FOR cause the assignment says so.
Thanks a lot.
May 28, 2014 at 11:23pm

Are you sure they ask you to use arrays, and not vectors for this?

The only way you can insert into a array is by knowing the maximum possible size during compile time and when inserting you move everything at that index and above by 1, then write the value.

If it has to be be arrays then that's the only way unless you are allowed to create a dynamically allocated array.

Topic archived. No new replies allowed.