Skip to content

Instantly share code, notes, and snippets.

@nalin-adh
Created November 10, 2015 17:09
Show Gist options
  • Save nalin-adh/cb519aa8553f7f68cc8c to your computer and use it in GitHub Desktop.
Save nalin-adh/cb519aa8553f7f68cc8c to your computer and use it in GitHub Desktop.
A C++ program to sort n numbers in ascending order using bubble sort.
#include<iostream>
#include<conio.h>
using namespace std;
void display(int b[]);
int main()
{
int a[]={9,5,3,7,4,6,1,2,8,9,4,5,6,2,0},n;
cout<<"Numbers before BUBBLE SORT :\n";
display(a);
cout<<"\nNumber after BUBBLE SORT : \n";
for(int i=0;i<14;i++){
for(int j=0;j<14-i;j++){
if(a[j]>a[j+1]){
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
display(a);
getch();
return(0);
}
void display(int b[]){
for(int i=0;i<15;i++){
cout<<b[i]<<" ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment