0
Source code for sorting integer and character in c++
without using vectors and algorithms
1 Réponse
+ 1
Here is the C++ 11 approach:
#include <iostream>
#include <algorithm> // for std::sort
#include <vector>
#include <string>
int main()
{
// int vector
std::vector<int> intVector({ 23, 2, 125, 39 });
// sort it
std::sort(intVector.begin(), intVector.end());
// print it
for (const int &val : intVector)
{
std::cout << val << " ";
}
// char vector
std::vector<char> charVector({ 'Z', 'd', 'E', 'w' });
std::sort(charVector.begin(), charVector.end());
// string
std::string testString = "zrta";
std::sort(testString.begin(), testString.end());
return 0;
}