Skip to content

Commit

Permalink
Create day31_solved (#223)
Browse files Browse the repository at this point in the history
Bubble Sort
  • Loading branch information
shubhendra-20 authored and MadhavBahl committed Feb 7, 2019
1 parent ae5352f commit 016bb3a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions day31/CPP/day31_solved
@@ -0,0 +1,52 @@
/*
Author: Shubhendra Singh
Github: shubhendra-20
*/

#include <iostream>
using namespace std;

void bubbleSort(int arr[], int n)
{
int i,j,t;
bool swap;
for (i = 0; i < n-1; i++)
{
swap = false;
for (j = 0; j < n-i-1; j++)
{
if (arr[j] > arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
swap=true;
}
}
if (swap == false)
break;
}
}

void printArray(int arr[], int n)
{
int i;
for (i=0; i < n; i++)
cout<<arr[i]<<" ";

}

int main()
{
int n,i;
cin>>n;
int arr[n];
for(i=0;i<n;i++)
{
cin>>arr[i];
}
bubbleSort(arr, n);
cout<<"Sorted array : ";
printArray(arr, n);
return 0;
}

0 comments on commit 016bb3a

Please sign in to comment.