I keep getting this debug error that my data is corrupted. I don't know how that is possible nor do I know how to fix it.
This program populates a array then uses a selection sort type algorithm to order the numbers. Has you can see it starts to sort the numbers and then stops with this corrupted data error. How can I fix it?
Full Code:
#define _CRT_SECURE_NO_WARNINGS
#define ARY_SIZE 10
#include <stdio.h>
#include <stdlib.h>
void selectionSort(int[], int last);
void ranNumPerm_10(int bubble_1[]);
int main(void)
{
int list[ARY_SIZE] = { 0 };
int last;
last = 10;
ranNumPerm_10(list);
for (int i = 0; i < ARY_SIZE; i++)
{
printf("%d\n", list[i]);
}
printf("\nUnsorted on top \n");
selectionSort(list, last);
for (int i = 0; i < ARY_SIZE; i++)
{
printf("%d\n", list[i]);
}
return 0;
}
void selectionSort(int list[], int last)
{
int smallest;
int tempData;
for (int current = 0; current < last; current++)
{
smallest = current;
for (int walk = current + 1; walk <= last; walk++)
if (list[walk] < list[smallest])
{
smallest = walk;
tempData = list[current];
list[current] = list[smallest];
list[smallest] = tempData;
}
}
return;
}
void ranNumPerm_10(int list[])
{
int oneRandno;
int haveRand[ARY_SIZE] = { 0 };
for (int i = 0; i < ARY_SIZE; i++)
{
do
{
oneRandno = rand() % ARY_SIZE;
} while (haveRand[oneRandno] == 1);
haveRand[oneRandno] = 1;
list[i] = oneRandno;
}
return;
}