passing an array through a selection sort and couting it

I am very new to programming(2nd project) and cant figure out how to cout my selection sort so that my array passes through it and then prints out in a sorted array. What i get with this code is around mostly numbers in the -80,000s and the range should be from 0 to 100. Anyone see anything wrong with my code?

#include <iostream>
#include <ctime>
using namespace std;

[code]void selectionsort(int array1[], int array_size)
{
for(int i = 0; i < array_size; i++)
{
int currentMin = array1[i];
int currentMinIndex = i;

for(int j = i + 1; j < array_size; j++ )
{
if (currentMin > array1[j])
{
currentMin = array1[j];
currentMinIndex = j;
}
}
if(currentMinIndex != i)
{
array1[currentMinIndex]=array1[i];
array1[i] = currentMin;
}
}
}

int main()
{
// this is for the 100 number random array needs to be in a function
const int array_size = 100;
int array1[array_size];
srand((unsigned)time(0));

for(int i=0; i<array_size; i++)
{
array1[i] = (rand()%100)+1;
selectionsort(array1, 100);
cout << array1[i] <<" ";
}

// this is for the 10000 number random array needs to be in a function
const int array2size = 10000;
int array2[array2size];
srand((unsigned)time(0));

for(int i=0; i<array2size; i++)
{
array2[i] = (rand()%10000)+1;
}



return 0;

}
[code] "Please use code tags" [/code]
1
2
3
4
5
6
for(int i=0; i<array_size; i++)
{ 
  array1[i] = (rand()%100)+1;
  selectionsort(array1, 100);  //¿why is this inside the loop?
  cout << array1[i] <<" ";
}
um that was my attempt to sort the array before couting it as i have no idea how to pass the array into the selection sort and then have it cout as a sorted array.
1
2
3
4
5
6
7
8
for(int i=0; i<array_size; i++){
  //initialization
}
selectionsort(array1, array_size); //operating

for(int i=0; i<array_size; i++){
  //output
}
Topic archived. No new replies allowed.