-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbleSort.cpp
More file actions
55 lines (31 loc) · 715 Bytes
/
bubbleSort.cpp
File metadata and controls
55 lines (31 loc) · 715 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
52
53
54
55
#include<iostream>
using namespace std;
void iSort(int arr[], int k){
for(int i = 0; i<k-1; i++){
for(int j =0;j<k-i;j++){
if(arr[j]>arr[j+1])
swap(arr[j+1],arr[j]);
}
}
}
int print(int arr[], int k){
for(int i =0; i<k ;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
int main(){
int n ;
int arr[100];
cout<<"Enter the length of the arr : ";
cin>>n;
cout<<"Enter the array elements : ";
for(int i = 0 ; i<n ; i++){
cin>>arr[i];
}
cout<<"Elements before sorting :"<<endl;
print(arr,n);
iSort(arr,n);
cout<<"Elements after sorting :"<<endl;
print(arr,n);
}