void bubbleSort(int aray[],int length)//Bubble sort function { int i,j; for(i=0;i<length;i++) { for(j=0;j<i;j++) { if(aray[i]>aray[j]) { int temp=aray[i]; //swap
aray[i]=aray[j]; aray[j]=temp; }
} } } int _tmain(int argc, _TCHAR* argv[]) { int n; int array1[100]; cout<<"Enter the number of elements : "; cin>>n; for(int i=0;i<n;i++){ cout<<"Enter the "<<i+1<<" element : "; cin>>array1[i]; } bubbleSort(array1,n); for(int i=0;i<n;i++){ cout<<array1[i]<<" "; } cout<<" Press any key to exit...."; getch();
Comments
Leave a comment