-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubbleSort.cpp
42 lines (34 loc) · 956 Bytes
/
BubbleSort.cpp
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
/**
* \file BubbleSort.cpp
* \brief
*
* \review
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
template<typename T >
void
bubbleSort(T &a)
{
for (typename T::size_type i = 0; a.size() && i < a.size() - 1; ++ i) {
for (typename T::size_type j = i; j + 1 > 0; -- j) {
if (a[j] > a[j + 1]) {
std::swap(a[j], a[j + 1]);
}
}
}
}
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::vector<int> v {7, 1000, 134, 23, 1};
::bubbleSort(v);
std::cout << STD_TRACE_VAR(v) << std::endl;
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
v: std::vector (size=5): {1,7,23,134,1000}
#endif