Skip to content

Instantly share code, notes, and snippets.

@sameerkumar18
Created November 28, 2015 06:31
Show Gist options
  • Save sameerkumar18/3b3fe0ebf3fce3781d17 to your computer and use it in GitHub Desktop.
Save sameerkumar18/3b3fe0ebf3fce3781d17 to your computer and use it in GitHub Desktop.
WAP to sort an array using Bubble Sort
/*Programmed by www.fb.com/sameer18051998*/
#include<iostream.h>
#include<conio.h>
void BubbleSort(int[],int);
void main()
{clrscr();
int AR[50],elem,n,index;
cout<<"\nWith How Many Elements Do You Want To Create An Array ?\n";
cin>>n;
cout<<"\nEnter The Array Elements\n";
for(int i=0;i<n;i++)
cin>>AR[i];
BubbleSort(AR,n);
cout<<"\n\nThe Sorted Array Is Shown Below \n";
for(i=0;i<n;i++)
cout<<AR[i]<<" ";
cout<<"\n";
getch();
}
void BubbleSort(int AR[],int size)
{ int tmp,ctr=0;
for(int i=0;i<size;i++)
{ for(int j=0;j<(size-1); --i,j++)
{ if(AR[j]>AR[j+1])
{tmp=AR[j];
AR[j]=AR[j+1];
AR[j+1]=tmp; }
}
cout<<"\nArray After Iteration - "<<++ctr<<" - is :";
for(int k=0;k<size;k++)
cout<<AR[k]<<" ";
cout<<"\n";
}
}
/*Programmed by www.fb.com/sameer18051998*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment