-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbubbleSort.cpp
More file actions
119 lines (56 loc) · 1.43 KB
/
bubbleSort.cpp
File metadata and controls
119 lines (56 loc) · 1.43 KB
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
#include <iostream>
using namespace std;
void swap(int num1, int num2){
int temp = num1;
num1 = num2;
num2 = temp;
}
void bubblesort(int numbers[], int length){
cout << length;
for(int i = 0; i < length; i++){
if(numbers[i] > numbers[i+1]){
swap(numbers[i], numbers[i+1]);
}
}
}
void print(int numbers[], int length){
for(int i = 0; i < length ;i++){
printf("%d \t", numbers[i] );
}
}
int main(){
int numbers[5] = {22, 13, 5, 7, 11};
int length = sizeof(numbers)/sizeof(*numbers);
bubblesort(numbers, length);
print(numbers, length);
return 0;
}
//#include <iostream>
//using namespace std;
//
//
//int main(){
// int num[] = {5,9,27,55,11,0};
// int temp;
// for(int i = 1; i < sizeof(num)/sizeof(*num) ; i++){
// cout << "Iteration = " << i << " : " << endl;
// for(int j =0; j < (sizeof(num) /sizeof(*num))-1 ; j++ ){
// if(num[j+1] < num[j]){
// temp = num[j];
// num[j] = num[j+1];
// num[j+1] = temp;
// }
// cout << "'J = " << j <<"'"<< endl;
// for(int i =0 ; i < sizeof(num) /sizeof(*num); i++){
// printf("%d\t", num[i]);
// }
// cout << endl;
// }
//
// cout << endl;
// }
// cout << "----------The sorted array is : " << endl;
// for(int i =0 ; i < sizeof(num) /sizeof(*num ); i++){
// printf("%d\t", num[i]);
// }
//}