-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.cpp
More file actions
39 lines (37 loc) · 862 Bytes
/
Copy pathBubbleSort.cpp
File metadata and controls
39 lines (37 loc) · 862 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
#include <iostream>
using namespace std;
void bubbleSort(int a[], int size)
{
int temp;
for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
if (a[j] < a[i])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
int main()
{
int A[50],i,j,sizeOfArray;
cout<<"\nBubble sort"<<endl;
cout<<"\nEnter size of the array(<50): ";
cin>>sizeOfArray;
cout<<"\nEnter elements of an array: ";
for(i=0;i<sizeOfArray;i++)
cin>>A[i];
cout<<"\nOriginal array"<<endl;
for(i=0;i<sizeOfArray;i++)
cout<<" "<<A[i];
cout<<endl;
bubbleSort(A,sizeOfArray);
cout<<"\nSorted array using bubble sort"<<endl;
for(i=0;i<sizeOfArray;i++)
cout<<" "<<A[i];
return 0;
}