0

I am creating 30 random from last function and the last function have pass the information to this one. I am using the bubble sort because i want to make a mode. But mode is not idea here. Anyway, it run but it show some crazy output. Here is the output:
-1969384903, -1969384675, -1957005749, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

here is the random number:

17-78-81-10-98-67-30-87-63-15
73-63-50-51-61-89-20-89-27-1
6-56-47-91-35-16-97-13-39-81

can someone tell me what i did wrong?

void mode(int mode[],int size2)
{
    int sorting_array[size2];
    int swap = 0;
    for(int counter = size2-1; counter >= 0 ; counter --)
    {
        for (int index = 0 ; index < size2; index ++)
        {
            if  (sorting_array[index] > sorting_array[index + 1])
            {
                swap = sorting_array [index + 1];
                sorting_array [index + 1] = sorting_array [index] ;
                sorting_array[index] = swap;

            }
        }
    }

    for (int index = 0 ; index < 30; index ++)
    {
        cout << sorting_array[index] << ", ";

    }
3
Contributors
3
Replies
22
Views
3 Years
Discussion Span
Last Post by chubbyy.putto
0

have you tried adding some debugging output to your code? For example, print out the value of the indices and values that you're trying to swap in that inner if statement...

Edited by ravenous: added detail

0

Look at the relationship of your line 7 and line 9. How does index relate to the bounds of the array?

for (int index = 0 ; index < size2; index ++)

    if  (sorting_array[index] > sorting_array[index + 1])
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.