And swapping is generally done using a third variable.
But you see, there is a third variable there, and it is called lowest. (Both you and the OP may have a problem getting "attached" to certain patterns in the code and not recognizing their variations )
Thank you for the reply anon. I tried it but it didn't work. Should incorporate pointers?
I don't understand. I just utilized the delete key and it seems to be working to me.
Code:
void sort(int array[], int numts)
{
int lowIndex, lowest;
for (int count = 0; count < (numts-1); count++)
{
lowIndex = count;
lowest = array[count];
for (int index = count + 1; index < numts; index++)
{
if (array[index] < lowest)
{
lowest = array[index];
lowIndex = index;
}
}
array[lowIndex] = array[count];
array[count] = lowest;
}
return;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
int main()
{
std::vector<int> vec;
std::copy(std::istream_iterator<int>(std::cin), std::istream_iterator<int>(), std::back_inserter(vec));
sort(&vec[0], vec.size());
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " "));
}