-
Notifications
You must be signed in to change notification settings - Fork 359
/
Copy pathArray_STL.cpp
78 lines (60 loc) · 1.01 KB
/
Array_STL.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
using namespace std;
template <class X> class ArrayList
{
private:
struct Control
{
int endlim;
X *arr;
};
Control *s;
public:
ArrayList(int endlim)//local var
{
s=new Control;
s->endlim=endlim;
s->arr=new X[s->endlim];
}
void setvalue(int index, X data)
{
if(index>=0 && index<=s->endlim-1)
{
s->arr[index]=data;
}
else
{
cout<<"wrong index \n";
}
}
void showvalue(int index,X &data)
{
if(index>=0 && index<=s->endlim-1)
{
data= s->arr[index];
cout<<"\nvalue @ index = "<<index<<" is = "<<data;
}
else
{
cout<<"wrong index \n";
}
}
void viewall()
{
int i;
for(i=0;i<s->endlim;i++)
{
cout<<"\nVALUE AT "<<i<<"=="<<s->arr[i];
}
}
};
int main()
{
ArrayList <int> obj1(4); //here we have to mention datatype of inputs
obj1.setvalue(0,21);
obj1.setvalue(1,22);
obj1.setvalue(2,23);
obj1.setvalue(3,24);
//obj1.showvalue(0,data);
obj1.viewall();
}