-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_sort.h
More file actions
48 lines (37 loc) · 775 Bytes
/
bubble_sort.h
File metadata and controls
48 lines (37 loc) · 775 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
40
41
42
43
44
45
46
47
48
#ifndef _CLASS_BUBBLE_SORT_
#define _CLASS_BUBBLE_SORT_
#include "sort.h"
class bubble_sort: public sort{
public:
explicit bubble_sort(int num):sort(num){
cout<<"create bubble_sort successfully"<<endl;
}
explicit bubble_sort(const int *array, int num):sort(array, num){
cout<<"create bubble_sort successfully"<<endl;
}
~bubble_sort(){
cout<<"free bubble_sort successfully, ";
}
void bubble(int *a, int n){
int tmp;
for (int i = n-1; i > 0; i--){
for (int j = 0; j < i; j++){
if (a[j+1] < a[j]){
tmp = a[j+1];
a[j+1] = a[j];
a[j] = tmp;
}
}
}
}
void bubblesort(){
bubble(a_, n_);
}
void print_a_(){
cout<<"bubble sorted array: ";
for (int i = 0; i < n_; i++)
cout<<a_[i]<<" ";
cout<<endl;
}
};
#endif