Skip to main content
deleted 46 characters in body
Source Link
user2173
user2173

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing? Thanks in advance.

int min, hold, i, j;
    for (i = 1; i < (n - 1); i++)
    {
        min = i;
        for (j = i + 1; j < n; j++)
        {
            if (values[j] < values[min])
                min = j;
            if (min != i)
            {
                hold = values[j];
                values[j] = values[i];
                values[i] = hold;
            } 
        }
     } 

I got ideas for this code from the video Selection Sort:

enter image description here

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing? Thanks in advance.

int min, hold, i, j;
    for (i = 1; i < (n - 1); i++)
    {
        min = i;
        for (j = i + 1; j < n; j++)
        {
            if (values[j] < values[min])
                min = j;
            if (min != i)
            {
                hold = values[j];
                values[j] = values[i];
                values[i] = hold;
            } 
        }
     } 

I got ideas for this code from the video Selection Sort:

enter image description here

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing?

int min, hold, i, j;
    for (i = 1; i < (n - 1); i++)
    {
        min = i;
        for (j = i + 1; j < n; j++)
        {
            if (values[j] < values[min])
                min = j;
            if (min != i)
            {
                hold = values[j];
                values[j] = values[i];
                values[i] = hold;
            } 
        }
     } 

I got ideas for this code from the video Selection Sort:

added 149 characters in body
Source Link
Azurespot
  • 203
  • 2
  • 10

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing? Thanks in advance.

int min, hold, i, j;
    for (i = 1; i < (n - 1); i++)
    {
        min = i;
        for (j = i + 1; j < n; j++)
        {
            if (values[j] < values[min])
                min = j;
            if (min != i)
            {
                hold = values[j];
                values[j] = values[i];
                values[i] = hold;
            } 
        }
     } 

I got ideas for this code from the video Selection Sort:

enter image description here

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing? Thanks in advance.

int min, hold, i, j;
    for (i = 1; i < (n - 1); i++)
    {
        min = i;
        for (j = i + 1; j < n; j++)
        {
            if (values[j] < values[min])
                min = j;
            if (min != i)
            {
                hold = values[j];
                values[j] = values[i];
                values[i] = hold;
            } 
        }
     } 

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing? Thanks in advance.

int min, hold, i, j;
    for (i = 1; i < (n - 1); i++)
    {
        min = i;
        for (j = i + 1; j < n; j++)
        {
            if (values[j] < values[min])
                min = j;
            if (min != i)
            {
                hold = values[j];
                values[j] = values[i];
                values[i] = hold;
            } 
        }
     } 

I got ideas for this code from the video Selection Sort:

enter image description here

Source Link
Azurespot
  • 203
  • 2
  • 10

Selection sort seems right, but the values are not sorted

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing? Thanks in advance.

int min, hold, i, j;
    for (i = 1; i < (n - 1); i++)
    {
        min = i;
        for (j = i + 1; j < n; j++)
        {
            if (values[j] < values[min])
                min = j;
            if (min != i)
            {
                hold = values[j];
                values[j] = values[i];
                values[i] = hold;
            } 
        }
     }