-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic array.cpp
More file actions
50 lines (50 loc) · 878 Bytes
/
dynamic array.cpp
File metadata and controls
50 lines (50 loc) · 878 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
using namespace std;
int main()
{
int size,n, finalsize;
cout<<"Enter size: "<<endl;
cin>>size;
int*mid = new int[size];
int *tmpmid = mid;
cout<<"Enter nos"<<endl;
for(int i=0; i<size; i++)
{
cin>>*tmpmid;
tmpmid++;
}
tmpmid = mid;
cout<<"Do you want to add new elements: "<<endl;
int choice;
cin>>choice;
if(choice==1)
{
cout<<"How many new elements: "<<endl;
cin>>n;
finalsize=size+n;
int *newmid=new int[finalsize];
int *tmpnewmid=newmid;
for(int i=0; i<finalsize; i++)
{
if(i<size)
{
*tmpnewmid=*tmpmid;
tmpnewmid++;
tmpmid++;
}
else
{
cout<<"Enter no:"<<endl;
cin>>*tmpnewmid;
tmpnewmid++;
}
}
tmpnewmid=newmid;
for(int i=0; i<finalsize; i++)
{
cout<<*tmpnewmid<<" ";
tmpnewmid++;
}
tmpnewmid=newmid;
}
}