tinycities
Programmer
Hi I'm trying to sort an array's elements into sequential order. When I run my program I am able to read the input from my input file, and then store that input in my array, but I can't get it to sort properly. I've pasted my sort function below. if you have any ideas please let me know. Thanks!
void sort (int arr[], int size, int& num_used)
{
bool sorted = false;
while (sorted == false)
{
sorted = true;
for (int index = 0; index < size - 1 && index < num_used - 1; index++)
{
if (arr[index] > arr[index+1])
{
int tmp = arr[index];
arr[index] = arr[index+1];
arr[index+1] = tmp;
sorted = false;
}//end if
}//end for
}//end while
}//end sort func.
void sort (int arr[], int size, int& num_used)
{
bool sorted = false;
while (sorted == false)
{
sorted = true;
for (int index = 0; index < size - 1 && index < num_used - 1; index++)
{
if (arr[index] > arr[index+1])
{
int tmp = arr[index];
arr[index] = arr[index+1];
arr[index+1] = tmp;
sorted = false;
}//end if
}//end for
}//end while
}//end sort func.