-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.cc
68 lines (48 loc) · 2.01 KB
/
vector.cc
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>
#include <vector>
using namespace std;
int main(){
vector<int> vi;
cout << "vi size=" << vi.size() << endl;
cout << "vi cap=" << vi.capacity() << endl;
cout << "vi empty=" << vi.empty() << endl;
vi.push_back(0); //dobawq element nakraq na vektora; moje da dobawim samo 1 element
cout << "vi size=" << vi.size() << endl;
cout << "vi cap=" << vi.capacity() << endl;
cout << "vi empty=" << vi.empty() << endl;
vi.push_back(1);
cout << "vi size=" << vi.size() << endl;
cout << "vi cap=" << vi.capacity() << endl;
vi.push_back(2);
cout << "vi size=" << vi.size() << endl;
cout << "vi cap=" << vi.capacity() << endl;
vi.push_back(3);
cout << "vi size=" << vi.size() << endl;
cout << "vi cap=" << vi.capacity() << endl; //vektora si dobawq oshte pamet kato uwelichawa capacity*2,towa stawa samo kogato stignem max capacity
for(int i=0;i<vi.size();++i) {
cout << "vi [" << i << "]=" << vi[i] << endl;
vi[i] = i * 42;
}
vi.at(0)= -42; // proverqva dali vi[0] e v capacityto na tozi masiv i posle mu dava stoinost -42
for(int i=0;i<vi.size();++i) {
cout << "vi [" << i << "]=" << vi[i] << endl;
}
//cout << vi[42] << endl; // kogato izlezem ot capacityto ni wrushta random stoinost
//cout << vi.at(42) << endl; // proverqva dali e v capacityto/pametta na masiva
vi.pop_back(); // pri pop capacityto ne namalqwa , samo size
cout << "vi size=" << vi.size() << endl;
cout << "vi cap=" << vi.capacity() << endl;
vector<double> vd(100); //imame 100 elementa
cout << "vd size=" << vd.size() << endl;
cout << "vd cap=" << vd.capacity() << endl;
for(int i=0;i<vd.size();++i) {
vi[i] = i * 3.14;
}
vd.push_back(100*3.14); //dobavqme oshte edin element
cout << "vd size=" << vd.size() << endl;
cout << "vd cap=" << vd.capacity() << endl;
for(vector<int>::iterator it=vi.begin() ; it!=vi.end() ; ++it) { //suzdavame iterator i mu davame stoinosta na nachalniq element na vi vektora ; : : razreshavat da wlojim klasa iterator v klasa vector
cout << "*it=" << *it << endl;
}
return 0;
}