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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Bubble array - sorting numbers

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]