-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_sort.cpp
More file actions
51 lines (42 loc) · 740 Bytes
/
bubble_sort.cpp
File metadata and controls
51 lines (42 loc) · 740 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<bits/stdc++.h>
using namespace std;
void bubble_sort(int a[], int n)
{
for(int j = 0; j<n; j++)
{
for(int k = 0; k<n-j-1; k++)
{
if(a[k]>a[k+1])
{
int temp = a[k];
a[k] = a[k+1];
a[k+1] = temp;
}
}
}
}
void print(int a[], int n)
{
for(int i = 0; i<n; i++)
{
cout<<a[i]<< " ";
}
cout<<endl;
}
int main()
{
cout<<"enter the size"<<endl;
int n;
cin>>n;
int a[100];
for(int i = 0; i<n; i++)
{
cin>>a[i];
}
cout<<"before sorting "<<endl;
print(a, n);
bubble_sort(a,n);
cout<<"after sorting"<<endl;
print(a, n);
return 0;
}