You are on page 1of 1

Bubble Sort

============================================
#include <iostream.h>
void swap( int *Ptr1, int *Ptr2 ){
int hold = *Ptr1;
*Ptr1 = *Ptr2;
*Ptr2 = hold;
}
void sort(int a[],const int s){
for(int pass=0;pass<s-1;pass++)
for(int comp=0;comp<s-1;comp++){
if(a[comp]>a[comp+1])
swap( &a[ comp ], &a[ comp + 1 ] );
}
}
void main(){
const int size=10;
int a[size]={2,1,6,8,4,5,7,3,10,9};
sort(a,size);
for(int i=0;i<size;i++)
cout<<a[i]<<' ';
cout<<endl<<endl;
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006