#include#include #include
using namespace std; int main() { string s; list LS; list ::iterator iter; while (true) { cout << "enter string (enter to exit): "; getline(cin, s); if (s.size() == 0) break; LS.push_back(s); } LS.sort(); for (iter = LS.begin(); iter != LS.end(); iter++) cout << *iter << endl; system("PAUSE"); return 0; }
上面的代码功能:可以输入名字,然后根据首字母顺序排序。主要使用了STL的链表和遍历器。



