Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
 
PREVIOUS NEXT
Tagged: #sort #string #array
ADD COMMENT
Topic
Name
9+5 =