Insertion Array

I need to insert a number in the middle of an array.
the program should be in fucntion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#include<iostream>
using namespace std;

int main()
{

	
	int array[5]={20,10,30,40,50};


	cout<<array[2]<<endl;









system("pause");
return 0;
}
  
Last edited on
What do you mean insert? Change the data of the number in the middle of the array, or insert a new number entirely?
insert number entirely :)
Someone else please correct me if I'm wrong, but I think you're looking for: http://www.cplusplus.com/reference/list/list/splice/
@tristan1333,

he is not using the std::list, but a normal array.

@Cruicial,
to insert an item you need first to declare a new array with at least one more element. However this requires pointer and dynamic memory management.
Last edited on
This thread seems to be a continuation of: http://www.cplusplus.com/forum/beginner/197039/


Edit: @Cruicial:
Lets say that the array A contains:
{20,10,30,40,50}

and array B has:
{20,10,30,60,40,50}

but array C has only:
{70}


Please insert value 42 both in the middle of A, B, and C and then show the content of each array to us. We need to understand the exact logic that the operation follows.
Last edited on
@Thomas1965
I know, just thought it might be a better idea to use a list anyway. But yeah you're right
Topic archived. No new replies allowed.