Skip to content

Commit

Permalink
Merge pull request #245 from Manoj-Suru/patch-1
Browse files Browse the repository at this point in the history
Create bubbleSort.cpp
  • Loading branch information
fineanmol authored Oct 1, 2021
2 parents 9c44e61 + 0454404 commit 1d73725
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Program's_Contributed_By_Contributors/C++_Programs/bubbleSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<bits/stdc++.h>
using namespace std;
//Function to swap two numbers
void swap (int *xp,int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
//Required function
void bubbleSort(int arr[],int n)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(arr[j]>arr[j+1]) swap(&arr[j],&arr[j+1]);
}
}
}

int main()
{
int n;
cout<<"Enter the size of array ";
cin>>n;
int a[n];
cout<<"Enter the elements of array "<<endl;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
bubbleSort(a,n);
cout<<"Array after sorting "<<endl;
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
}

0 comments on commit 1d73725

Please sign in to comment.