-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainn.cpp
More file actions
98 lines (85 loc) · 1.97 KB
/
mainn.cpp
File metadata and controls
98 lines (85 loc) · 1.97 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
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
#include<iostream>
#include"vector.h"
using namespace std;
Vector<?>::difference_type operator-(const Vector::ConstIterator& lop, const Vector::ConstIterator& rop){
return lop.ptr - rop.ptr;
}
bool operator<(const Vector<?>::ConstIterator& lop, const Vector::ConstIterator& rop){
return lop.ptr<rop.ptr;
}
bool myfn(Vector::const_reference l, Vector::const_reference r){return l<r;}
int main(){
Vector<?> a = Vector();
try{
cout << a[0] << '\n';
}
catch(exception& e){
cout << "woups" << '\n';
}
a.push_back(12);
cout << a[0] << '\n';
Vector<?> b = Vector(a);
cout << b[0] << '\n';
Vector<?> c = Vector{1,3,4};
cout << c[2] << '\n';
c = b;
cout << c[0] << '\n';
c[0] = 5;
cout << c[0] << '\n';
cout << b[0] << '\n';
cout << "Size, empty, clear \n";
cout << a.size() << '\n';
a.empty() ? cout << "yes \n" : cout << "no \n";
a.clear();
cout << a.size() << '\n';
a.empty() ? cout << "yes \n" : cout << "no \n";
cout << "Pop back and [] \n";
Vector d = Vector{5,6,7,8};
d.pop_back();
try{
cout << d[3] << '\n';
}
catch(exception e){
cout << "woups2" << '\n';
}
d.print(cout);
cout << endl << "---------Test Erase-------" << endl;
cout << "Erase pos: 1"<< endl;
d.erase(d.getIteratorOnPos(1));
d.print(cout);
cout << endl << "---------Test Insert-------" << endl;
cout << "Insert:8 - pos: 1"<< endl;
d.insert(d.getIteratorOnPos(1),8);
d.print(cout);
cout << endl << "---------Test Algorithms-------" << endl;
Vector algo{7, 1.4, 8.2, 9, -4.5, -0.5};
algo.print(cout);
cout << endl;
cout << "Sum: " << algo.sum() << endl;
auto be=d.begin();
auto en=d.end();
cout << "Begin: " << *be << endl;
cout << "End: " << *en << endl;
auto it = max_element(be,en, [] (Vector::const_reference l, Vector::const_reference r){return l>r;});
cout << "Max: " << *it << endl;
cout << "Max: " << d.max() << endl;
cout << "Min: " << d.min() << endl;
return 0;
}
/*
Ausgabe:
woups
12
12
4
12
5
12
Size, empty, clear
1
no
0
yes
Pop back and []
woups2
*/