-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemplateBubbleSort.h
151 lines (132 loc) · 2.56 KB
/
TemplateBubbleSort.h
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#pragma once
#include <iostream>
#include <string>
using namespace std;
struct Player
{
string nick;
int money;
int expirience;
int level;
};
bool operator > (const Player& one, const Player& two)
{
return one.expirience > two.expirience;
}
/*void bubble_sort(int ar[], const unsigned int size)
{
for (int pr = 0; pr < size - 1; pr++)
{
for (int i = size - 1; i > pr; i--)
{
if (ar[i] > ar[i - 1])
{
//swap(ar[i], ar[i - 1]);
int temp = ar[i];
ar[i] = ar[i - 1];
ar[i - 1] = temp;
}
}
}
}
void bubble_sort(double ar[], const unsigned int size)
{
for (int pr = 0; pr < size - 1; pr++)
{
for (int i = size - 1; i > pr; i--)
{
if (ar[i] > ar[i - 1])
{
//swap(ar[i], ar[i - 1]);
double temp = ar[i];
ar[i] = ar[i - 1];
ar[i - 1] = temp;
}
}
}
}
void bubble_sort(Player ar[], const unsigned int size)
{
for (int pr = 0; pr < size - 1; pr++)
{
for (int i = size - 1; i > pr; i--)
{
if (ar[i] > ar[i - 1])
{
//swap(ar[i], ar[i - 1]);
Player temp = ar[i];
ar[i] = ar[i - 1];
ar[i - 1] = temp;
}
}
}
} */
template <typename T> // ïàðàìåòð òèïà
void bubble_sort(T ar[], const unsigned int size)
{
for (int pr = 0; pr < size - 1; pr++)
{
for (int i = size - 1; i > pr; i--)
{
if (ar[i] > ar[i - 1])
{
T temp = ar[i];
ar[i] = ar[i - 1];
ar[i - 1] = temp;
}
}
}
}
/*
// code for main:
const int size = 5;
int ar[size] = { 5, 15, 47, 28, 37 };
bubble_sort(ar, size);
for (int i = 0; i < size; i++)
{
cout << ar[i] << "\t";
}
cout << "\n\n";
/////////////////////////////////////////////////
double br[size] = { 5.2, 15.3, 47.4, 28.5, 37.6 };
bubble_sort(br, size);
for (int i = 0; i < size; i++)
{
cout << br[i] << "\t";
}
cout << "\n\n";
Player first;
first.expirience = 123123;
first.level = 1;
first.money = 1234;
first.nick = "Vasya";
Player second;
second.expirience = 234;
second.level = 2;
second.money = 2345;
second.nick = "Petya";
Player third;
third.expirience = 345;
third.level = 3;
third.money = 3456;
third.nick = "Masha";
Player fourth;
fourth.expirience = 456;
fourth.level = 4;
fourth.money = 4567;
fourth.nick = "Alex";
Player fifth;
fifth.expirience = 567;
fifth.level = 5;
fifth.money = 5678;
fifth.nick = "Mira";
Player players[size] = { first, second, third, fourth, fifth };
bubble_sort(players, size);
for (int i = 0; i < size; i++)
{
cout << i + 1 << ") " << players[i].nick << " - ";
cout << players[i].expirience << ", ";
cout << players[i].money << ", ";
cout << players[i].level << "\n";
}
*/