#include #include #include #include #include using namespace std; void insertToPlace(list* v, const string* word){ if(!v->size() || *word < v->front()){ v->push_front(*word); return; } if(*word == v->front()){ return; } for(list::iterator it = next(v->begin()); it != v->end(); it++){ if(*word == *it){ return; } if(*word > *prev(it) && *word < *it){ v->insert(it, *word); return; } } v->push_back(*word); } int main(){ ios::sync_with_stdio(false); cout<<"Introduce a line: "; string line; getline(cin, line); list v; istringstream sstream(line); string word; while(getline(sstream, word, ' ')){ insertToPlace(&v, &word); } cout<<"Distinct words ordered alphabetically:\n"; for(list::iterator it = v.begin(); it != v.end(); it++){ cout<<*it<<"\n"; } cout.flush(); return 0; }