Source code for sorting integer and character in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Source code for sorting integer and character in c++

without using vectors and algorithms

1st Dec 2016, 2:10 PM
Bibek Ghimire
Bibek Ghimire - avatar
1 Answer
+ 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; }
1st Dec 2016, 2:30 PM
David Barzi
David Barzi - avatar