Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions bubble_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
using namespace std;

void b_sort(int n, int a[]);

int main()
{
int a[100], n;

cout << "Enter the number of elements to be inserted: ";
cin >> n;

cout << "Enter the elements: \n";
for(int i=0; i<n; i++)
{
cin >> a[i];
}

b_sort(n, a);

cout << "SORTED ARRAY: \n";
for(int i=0; i<n; i++)
{
cout << a[i] << " ";
}

return 0;
}

void b_sort(int n, int a[])
{
int temp;

for(int i=0; i<n; i++)
{
for(int j=0; j<n-1-i; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}