In: Computer Science
C++ Sort Vector of Strings (case-sensitive)
Without using libraries, how would I arrange a vector like this alphabetically?
vector words {"September", "test" "seven", "apple"}
The output should be: "apple, seven, September, test"
#include <iostream>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<string> array;
    string temp;
    int i,j;
    array.push_back("september");
    array.push_back("test");
    array.push_back("seven");
    array.push_back("apple");
  
  
    for(i=0;i<array.size();i++)
    {
        //temp=array[i];
       
for(j=i+1;j<array.size();j++)
        {
           
if(array[i]>array[j])
           
{
               
temp=array[i];
               
array[i]=array[j];
               
array[j]=temp;
           
}
        }
    }
    cout<<array[0]<<endl;
    cout<<array[1]<<endl;
    cout<<array[2]<<endl;
    cout<<array[3]<<endl;
    return 0;
}
code:


output:

If you have any queries...please comment...Thank you...