void Sort()
{
vector<int> data;
string number;
cin.ignore();
getline(cin, number);
data = insertion_sort(number);
// ASCENDING
for (int i = 0; i < data.size(); i++)
{
cout << data[i] << " ";
}
// // DESCENDING
// for (int i = data.size()-1; i >=0 ; i--)
// {
// cout << data[i] << " ";
// }
}
int main()
{
map<string, function<void()>> functions;
functions["SORT"] = Sort;
functions["IS_SORTED"] = Is_Sorted;
functions["GETMAX"] = GetMax;
functions["APPEND"] = AppendSorted;
functions["GET_HISTOGRAM"] = GetHistogram;
int num;
cin >> num;
while (num > 0)
{
string func;
cin >> func;
if (functions.find(func) != functions.end())
{
functions[func]();
}
cout << endl ;
num--;
}
return 0;
}
I want my Sort()
function to be like this: Sort(descending=False)
. And in the input, users can ask if they want descending or ascending, and if they didn't say, the function should be ascending by default. For example:
input:
2
SORT
1 -2 13 24 -100
SORT DESCENDING
1 2 3 5 6
output:
-100 -2 1 13 24
6 5 3 2 1