void sectionSort(int a[], int n)
{
int i, j, min, temp;
for (int i = 0; i < n - 1; i++)
{
int minIndex = 0;
for (int j = i + 1; j < n; j++)
{
if (a[j] < a[minIndex])
{
minIndex = j;
}
}
cout << a[i];
swap(a[minIndex], a[i]);
}
}
int main()
{
srand(time(0));
int i;
int n = 1001;
int a[1001];
printf("The original array is: \n");
for (i = 0; i < n; i++)
{
a[i] = rand() % n;
};
for (i = 0; i < n; i++)
{
printf("a[%d]=%d\t", i, a[i]);
};
printf("\n");
printf("The sorted array is: \n");
sectionSort(a, n); //This is where it's printing the num.
for (i = 0; i < n; i++)
{
printf("a[%d]=%d\t", i, a[i]);
};
return 0;
}
void sectionSort( int a[], int n )
{
for (int i = 0; i < n - 1; i++)
{
auto next = std::min_element( a+1, a+n );
auto minIndex = std::distance( a, next );
cout << a[i];
swap( a[minIndex], a[i] );
}
}
Pay attention how you print the element before you have set its proper value.