Skip to content

Commit e5f3fcb

Browse files
committed
Added bubble sort algorithm
1 parent f5f1113 commit e5f3fcb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Sorting/bubble_sort.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
cout<<"Enter the length of array"<<endl;
7+
int m, temp,n;
8+
cin>>n;
9+
int arr[n];
10+
cout<<"Enter the elements of array"<<endl;
11+
for (int i = 0; i < n; i++)
12+
{
13+
cin>>arr[i];
14+
}
15+
for (int i = 0; i < n; i++)
16+
{
17+
for (int j= 0; j< n-1; j++)
18+
{
19+
if (arr[j]>arr[j+1])
20+
{
21+
temp = arr[j];
22+
arr[j] = arr[j+1];
23+
arr[j+1] = temp;
24+
}
25+
}
26+
}
27+
for (int i = 0; i < n; ++i)
28+
{
29+
cout<<arr[i]<<" ";
30+
}
31+
return 0;
32+
}

0 commit comments

Comments
 (0)