Search (Article Or Program)

18 June 2011

Bubble Sort (in C++)

//bubble sort program//
#include
#include
main()
{
clrscr();
int n=4;
int data[5];
int t;
int ptr;
cout<<"\nInsert Numbers five Numbers for sorting\n"; for(int i=0;i<=n;i++) { cin>>data[i];
}
for(int k=1;k<=n-1;k++) { ptr=0; while(ptr<=n-k) { if (data[ptr]>data[ptr+1])
{
t=data[ptr];
data[ptr]=data[ptr+1];
data[ptr+1]=t;
}
ptr++;
}
for(int i=0;i<=n;i++)
{
cout< cout<<"\n";
}
getch();

} }