Re: How to use bubble sort
Did you write this yourself, or copy paste it from somewhere?
I ask, because your code is mostly correct everywhere, yet you choke on things you have already proved you know...?
1. You will need to forward declare your "bubblesort" function, so the compiler knows what "bubblesort" when you call it.
2. Call bubble sort before trying to output your array. Writting "cout << bubblesort" makes no sense at all.
3. The arguments to your bubble sort are your array, and its size.
4. To output your array, you need to loop over its elements. You did it for input, why didn't you do it for output?
5. I recommend you always put braces {} after an if statement. This will avoid the bugs such as the ones you have right now. Your indentation does NOT represent what is really going on.
6. if ( list [index] == list [ index+1 ]) Are you sure that's equality you want to test?
Re: How to use bubble sort
Our doctor wrote the function ,, and i wanted to use it , i did find the mistake like > greater then and the declaration
PHP Code:
# include <iostream>
using namespace std;
void bubblesort ( int array[] , int length );
int main () {
int array [10]={10,20,30,40,50};
for ( int i=0; i<10; i++)
cout <<bubblesort(array,10);
return 0;
}
void bubblesort ( int array[], int length ) {
int step , index , temp;
for ( step =1; step<length; step++)
{
for ( index=0; index<length-step; index++)
if ( array [index] > array [ index+1 ])
{
temp = array [ index];
array [index] = array [index+1];
array [index+1] = temp;
}
}
}
Re: How to use bubble sort
I'd help, but at this point, I think it would be best if you took the time to stop, and review the basics.
Acquire some solid foundations, don't just write code hoping it will work.
Please start here: http://www.cplusplus.com/doc/tutorial/
If after that, you still don't know how to do what you need, then please come back and tell us what it is you are having trouble with, and we'll take all the time in the world to help you.
Re: How to use bubble sort
Okay i will go through all the steps there =)
Thanks Alot