-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector_class.txt
104 lines (73 loc) · 1.54 KB
/
vector_class.txt
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
Vector class:-
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
class Vector{
int*arr;
int cs;
int ms;
public:
Vector(){
cs = 0;
ms = 1;
arr = new int[ms];
}
void push_back(int d){
if(cs == ms){
int *oldarr = arr;
ms = 2*ms;
arr = new int[ms];
for(int i =0;i<cs;i++){
arr[i] = oldarr[i];
}
delete oldarr;
}
arr[cs]=d;
cs++;
}
void pop_back(){
if(cs>=0)cs--;
}
bool isempty(){
return cs==0;
}
int getfront(){
return arr[0];
}
int back(){
return arr[cs-1];
}
int size(){
return cs;
}
int capacity(){
return ms;
}
};
int main()
{
// vector<int> v = {1,2,3,4,5,6,7};
// int key;
// cin>>key;
// vector<int>::iterator it = find(v.begin(),v.end(),key);
// if(it!=v.end())cout<<it - v.begin();
// else cout<<"element is not found";
// vector<vector<int>>arr = {{1,2,3},
// {4,5,6,7},
// {8,9,10},
// {11,12}};
// for(int i =0;i<arr.size();i++){
// for(int number : arr[i]){
// cout<<number<<" ";
// }
// cout<<endl;
// }
Vector v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
v.push_back(5);
cout<<v.size()<<endl;
return 0;
}