I am trying to do a template function that sorts 3 elements,
numbers(int, double) work fine but string's do not behave as expected
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
template<typename TYPE>
void sort3(TYPE n1, TYPE n2, TYPE n3) {
TYPE arr[3];
arr[0] = n1;
arr[1] = n2;
arr[2] = n3;
sort(arr, arr + 3);
for (int i = 0; i < 3; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
int main(int argc, char** argv) {
sort3("B", "Z", "A");
sort3(10.2, 99.0, 1.9);
sort3(200, 50, 1);
return 0;
}
gives me the following output:
A Z B
1.9 10.2 99
1 50 200
to my understanding sort3("B", "Z", "A"); should give me A B Z
it is not OS specific since it gives me the same result in online compiler
what is happening there ?