...

View Full Version : Bubble sorting try



Adeel.Rekhi
01-15-2012, 08:02 PM
i m trying to make a program for bubble sort the code is
[code]
#include<iostream.h>
#include<conio.h>

main()
{
int size;
cout<<"Enter the size of array: ";
cin>>size;
cout<<endl;
int arr[size];
for(int i=0;i<size;i++)
{
cout<<"Enter the number in "<<i+1<<"th Index: ";
cin>>arr[i];
cout<<endl;
}
for(int j=0;j<size-1;j++){
for(int k=0;k<size-j;k++){
if(arr[k]>arr[k=1]){
int temp=;
temp=arr[k];
arr[k]=arr[k+1];
arr[k+1]=temp;
}
}
}
for(int m=0;m<size;m++)
{
cout<<"Your "<<m+1<<"th array is "<<arr[m]<<endl;
}getch();
}
[code\]
but its having bug...
dont know where?

oracleguy
01-15-2012, 09:31 PM
Well this is wrong:

if(arr[k]>arr[k=1]){

It should be:

if(arr[k]>arr[k+1]){

And please try and give more details in the future when posting a problem. Saying it has a bug isn't very descriptive.

Adeel.Rekhi
01-16-2012, 10:32 AM
Well...
i tried u correction but as before it promp the user to take values but do not generate the result of sorting.......:confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum