Skip to content

Commit 0e70345

Browse files
authored
Create bubbleSort
1 parent 23c8357 commit 0e70345

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Sorting/bubbleSort

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
void bubbleSort(int arr[], int n){
4+
for(int i=0;i<n-1;i++){
5+
for(int j=0;j<n-1-i;j++){
6+
if(arr[j]>arr[j+1]){
7+
swap(arr[j],arr[j+1]);
8+
}
9+
}
10+
}
11+
}
12+
int main()
13+
{
14+
int a[]={3,2,5,6,4};
15+
int m=sizeof(a)/sizeof(a[0]);
16+
bubbleSort(a, m);
17+
for(int i=0;i<m;i++){
18+
cout<<a[i]<<" ";
19+
}
20+
}

0 commit comments

Comments
 (0)