1.)
When I said put an input outside the loop, I meant an input before the loop. You get your first number, then set the low and high variables to that first input.
Inside the loop, you'll set low to the number if it's lower than low, high to the number if it's higher than high. You want to put this in the loop. The loop will have to be adjusted for this extra input.
template<class type1, class type2> //list type, object contained type
type1 sort_t(type1& t1)
{
type2 listob;
if(t1.size() < 2) //nothing to sort
{
return t1;
}
listob = *t1.begin(); //dereference the beginning iterator and assign it to our temp storage
t1.erase(t1.begin());
for(type1::iterator it = t1.begin(); it != t1.end(); it++)
{
if(*it < listob)
{
swap(listob, *it);
}
}
//now we have taken out the item of least value.
sort_t(t1);
try
{
t1.push_back(listob);
}
catch(...)
{
try
{
t1 += listob;
}
catch(...)
{
return {};
}
}
return t1;
}
This should work with either a string or a vector, but no garuntees can be made (do to member functions of those objects being different for appending items).
if you're using an array, you can modify the code above.