forked from Silver-Taurus/algorithms_and_data_structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubbleSort.h
44 lines (38 loc) · 1.67 KB
/
bubbleSort.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
/***
* _ __ ___ _
* | |/ /___ ___ _ __ / __|__ _| |_ __
* | ' </ -_) -_) '_ \ | (__/ _` | | ' \
* |_|\_\___\___| .__/ \___\__,_|_|_|_|_|
* |_|
* _
* __ _ _ _ __| |
* / _` | ' \/ _` |
* \__,_|_||_\__,_|
*
* _ _ _ _ _ _
* | | ___ __ _ _ _ _ _ /_\ | |__ _ ___ _ _(_) |_| |_ _ __ ___
* | |__/ -_) _` | '_| ' \ / _ \| / _` / _ \ '_| | _| ' \| ' \(_-<
* |____\___\__,_|_| |_||_| /_/ \_\_\__, \___/_| |_|\__|_||_|_|_|_/__/
* |___/
* Yeah! Ravi let's do it!
*/
#ifndef BUBBLE_SORT_H
#define BUBBLE_SORT_H
#include <generic.h>
namespace algo {
template <typename T>
static void bubbleSort(T list[], int start, int end)
{
bool swapped;
do {
swapped = false;
for (int i = start + 1; i <= end; ++i) {
if (list[i-1] > list[i]) {
swapped = true;
swap(list[i-1], list[i]);
}
}
} while (swapped);
}
} //end of namespace algo
#endif