Bubble array - sorting numbers - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Bubble array - sorting numbers

imattbimattb Posts: 2Member
So I'm having a little trouble when I run my program, to sort the numbers from greatest to highest, when it hits 0 at the end it push it some where and out put some random integer...

[code]

/*
* File: main.cpp
* Author: Matt
*
* Created on July 26, 2012, 12:48 PM
*/

#include
#include

using namespace std;

int main(int argc, char** argv) {

int Hold;//Holds value to swap
int end = 10;
int length = 10;


int sortArray[] = {1, 7, 4, 0, 9, 4, 8, 8, 2, 4};//Sort greatest to lowest

for(int count = length - 1; count > 0; count-- )
{
for (int i = 0; i < end; i++)//Goes through sortArray
{
if (sortArray[i] < sortArray[i +1])//i = 1 less than i = 7
{
Hold = sortArray[i];//Hold = 1 i = 1
sortArray[i] = sortArray[i +1];//7 = 7
sortArray[i + 1] = Hold;//7 = 1
}
for(int i = 0; i < 10 ; i++)
{
cout<< sortArray[i]<<", ";
}
cout<<endl;
}
end--;
}

// for(int i = 0; i < 10 ; i++)
// {
// cout<< sortArray[i]<<" ";
// }
// cout<<endl;
return 0;
}

[/code]

thanks in adavance
Sign In or Register to comment.