-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble sort.cpp
More file actions
51 lines (46 loc) · 772 Bytes
/
bubble sort.cpp
File metadata and controls
51 lines (46 loc) · 772 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<iostream>
using namespace std;
int *a, n;
void input()
{
cout<<"\nEnter the number of elements : ";
cin>>n;
a= new int[n];
cout<<"\nEnter the elements: ";
for(int i =0; i<n; i++)
{
cin>>a[i];
}
}
void display()
{
cout<<"\nThe elements in the array are: ";
for(int i =0; i<n; i++)
{
cout<<a[i]<<"\t";
}
}
void bubblesort(int a[], int n)
{
int t;
for(int i =0; i<n; i++)
{
for(int j =0; j<n-i-1; j++)
{
if(a[j]> a[j+1])
{
t= a[j];
a[j]= a[j+1];
a[j+1] = t;
}
}
}
cout<<"\n Sort Complete";
}
int main()
{
input();
bubblesort(a, n);
display();
return 0;
}