// lexsort.cpp #include "stdafx.h" #include #include using namespace std; const char low = 'a'; const char high = 'z'; const int k = high - low + 1; // pocet prihradek const int z = 3; // delka retezce class item{ public: char slovo[z]; item*next; item():next(nullptr){for (int i=0;inext = p; last = p; p->next = nullptr; } void list::clear(){ first =nullptr; last = nullptr; } void list::join(list & p) { if (p.first != nullptr) { if (first == nullptr) { first = p.first; last = p.last; } else { last->next = p.first; last = p.last; } } } list vstup; list box[k]; void sort(int i) { for(int j = 0; j slovo[i] - low; item *q = p->next; box[j].add(p); p=q; } vstup.clear (); for (int j = 0; j = 0 ; j--) sort (j); } void insert (string s) { item * p = new item (); int len = s.length (); for (int j = 0; j < z; j ++) { char c = low; if (j < len) c = s[j]; p->slovo [j] = c; } vstup.add (p); } void print () { item * p = vstup.first; while (p != nullptr) { for (int j = 0; j < z; j ++) cout << p->slovo[j]; cout << endl; p = p->next; } } int _tmain(int argc, _TCHAR* argv[]) { insert ("abc"); insert ("aba"); insert ("zax"); sort (); print (); system ("pause"); return 0; }