forked from BitSails/hellogit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
113 lines (83 loc) · 1.39 KB
/
main.cpp
File metadata and controls
113 lines (83 loc) · 1.39 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <vector>
#include "Data.h"
using namespace std;
void print (auto A)
{
for (auto a : A)
cout << a << " ";
cout<<endl;
}
void printClass (auto A)
{
for (auto a : A)
cout << a.getX() << " "<< a.getY() << " ";
cout<<endl<<endl;
}
void insertionSort (auto& D)
{
for (int i=1; i < D.size(); i++)
{
int j=i;
while (j > 0 and D[j] < D[j-1])
{
swap (D[j], D[j-1]);
j--;
}
print(D);
}
}
void insertionSortClass (auto& D)
{
for (int i=1; i < D.size(); i++)
{
int j=i;
while (j > 0 and D[j].getX() < D[j-1].getX())
{
swap (D[j], D[j-1]);
j--;
}
printClass(D);
}
}
int main()
{
vector<int> v1;
vector<int> v2={22,8,7,9,45};
v1.push_back(17);
vector <int> w = {7, 6, 5, 4, 3, 2};
insertionSort(w);
for (auto i:w)
{
cout << i << " ";
}
cout <<endl<<endl<<endl;
cout << "V2 has " << v2.size() << " elements. They are:" << endl<<endl;
for (auto x:v2)
{
cout << x << endl;
}
cout << endl;
Data d0;
Data d1 = {7,24.83};
d0.setX(15);
d0.setY(3.14);
vector<Data> v;
v.push_back( {7,21.01} );
Data d;
v.push_back(d);
d.setX(6);
d.setY(12.10);
v.push_back(d);
d.setX(5);
d.setY(6.12);
v.push_back(d);
cout <<endl<<"The Vector V of type Data contains: "<< endl<<endl;
for (auto a:v)
{
cout << a.getX() << " ";
cout << a.getY() << endl<< endl;
}
insertionSortClass(v);
return 0;
}