Answers for "sort in c++ string"

C++
9

how to sort a string in c++

#include<bits/stdc++.h>
using namespace std;
int main()
{
	srting str; // First, declare a string.
  	sort(str.begin() , str.end()); // Then sort it by using this method. It is much more convenient.
  	cout << str << endl; // Last of all, print out the string.
}
Posted by: Guest on May-26-2021
0

how to sort string array in c++

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s[n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n - 1; j++)
            if (s[j] > s[j + 1])
                swap(s[j], s[j + 1]);
    for (int i = 0; i < n; i++)
        cout << s[i] << endl;
    return 0;
}
Posted by: Guest on May-13-2022

Browse Popular Code Answers by Language