-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBubbleSort.h
More file actions
40 lines (34 loc) · 909 Bytes
/
BubbleSort.h
File metadata and controls
40 lines (34 loc) · 909 Bytes
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: BubbleSort.h
* Author: Chris Frey
*
* Created on February 12, 2018, 8:16 PM
*/
#ifndef BUBBLESORT_H
#define BUBBLESORT_H
#include "SortableVector.h"
class BubbleSort{
public:
virtual bool needSwap(SortableVector* sv, int i, int j) const =0;
void sort(SortableVector* sortableVector){
bool sorted = false;
int n=sortableVector->getSize();
while( !sorted ){
sorted = true;
for(int i=1; i<n; i++){
if(needSwap(sortableVector,i-1,i))
{
sortableVector->swap(i-1,i);
sorted = false;
}
}
n--;
}
}
};
#endif /* BUBBLESORT_H */