-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbubble sort.cpp
More file actions
51 lines (41 loc) · 986 Bytes
/
bubble sort.cpp
File metadata and controls
51 lines (41 loc) · 986 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
49
50
51
#include <stdio.h>
#include <iostream>
using namespace std;
void bubbleSort(int array[],int iteration, char order){
int temp,sort;
if(order =='d'){
sort = 1;
}else{
sort = 2;
}
if(sort == 1){
for(int i=0;i<iteration;i++){
if(array[i]<array[i+1]){
temp = array[i];
array[i] = array[i+1];
array[i+1] = temp;
}
}
}else{
for(int i=0;i<iteration;i++){
if(array[i]>array[i+1]){
temp = array[i];
array[i] = array[i+1];
array[i+1] = temp;
}
}
}
}
int main(){
int array[10],iteration;
char order;
cout<<"Array Size: ";
cin>>iteration;
for(int i=0;i<iteration;i++){
cin>>array[i];
}
cout<<"Sorting order: ";
cin>>order;
bubbleSort(array, iteration, order);
return 0;
}