ahmed0saber

Sort words in dictionary order in C++

Nov 13th, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     string str[10],temp;
  6.     cout<<"Enter 10 words : "<<endl;
  7.     for(int i=0;i<10;++i)
  8.     {
  9.       getline(cin,str[i]);
  10.     }
  11.     for (int i=0;i<9;++i)
  12.     {
  13.         for (int j=0;j<9-i;++j)
  14.         {
  15.             if (str[j]>str[j+1])
  16.             {
  17.                 temp=str[j];
  18.                 str[j]=str[j+1];
  19.                 str[j+1]=temp;
  20.             }
  21.         }
  22.     }
  23.     cout<<"In lexicographical order : "<<endl;
  24.     for(int i=0;i<10;++i)
  25.     {
  26.        cout<<str[i]<<endl;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment