Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-15-2012, 08:02 PM   PM User | #1
Adeel.Rekhi
New Coder

 
Join Date: Nov 2011
Location: Pakistan
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
Adeel.Rekhi is an unknown quantity at this point
Bubble sorting try

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?
Adeel.Rekhi is offline   Reply With Quote
Old 01-15-2012, 09:31 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
Well this is wrong:
Code:
if(arr[k]>arr[k=1]){
It should be:
Code:
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.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 01-16-2012, 10:32 AM   PM User | #3
Adeel.Rekhi
New Coder

 
Join Date: Nov 2011
Location: Pakistan
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
Adeel.Rekhi is an unknown quantity at this point
Unhappy

Well...
i tried u correction but as before it promp the user to take values but do not generate the result of sorting.......
Adeel.Rekhi is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:32 AM.


Advertisement
Log in to turn off these ads.