-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
68 lines (51 loc) · 1.04 KB
/
vector.cpp
File metadata and controls
68 lines (51 loc) · 1.04 KB
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
#include<iostream>
using namespace std;
class _vector {
int* vec;
int len;
public:
_vector(){
vec = new int[100];
len = 0;
}
_vector(int no){
vec = new int[100];
vec[0] = no;
len++;
}
void add_front(int no){
if (len == 0){
vec[len] = no;
++len;
}
else {
for(int i=len;i>0;i--){
vec[i] = vec [i-1];
}
vec[0] = no;
++len;
}
}
void add_rear(int no){
if (len < 100)
vec[len] = no;
++len;
}
void display(){
for (int i=0;i<len;i++)
cout <<vec[i]<<"\t";
}
void capacity(){
cout<<"\n Capacity of vector: " <<len <<endl;
}
};
int main() {
_vector v1 ;
v1.add_front(4);
v1.add_front(6);
v1.add_front(9);
v1.add_rear(12);
v1.add_rear(10);
v1.display();
v1.capacity();
}