#include<bits/stdc++.h> using namespace std; bool comparator(string &s1, string &s2) { return s1.length() < s2.length(); } void print(vector<string>&words) { for(int i =0 ; i< words.size() ; i++) { cout << words[i] << " " ; } } int main() { vector<string>words = {"a", "sgud", "sjs", "ahjdh", "ahsjkskla"}; sort(words.begin(), words.end(), comparator); print(words); } |
Comments
Post a Comment