int main() { list<int> test; //插入 test.push_back(1); test.push_back(1); test.push_front(0); test.push_back(2); auto it = test.begin(); for (int count = 0; it != test.end() && count < 2; it++, count++); test.insert(it, 3);//在迭代器之前插入 //排序 test.sort(); //遍歷 for (auto &i : test) cout << i << endl; //刪除 for (auto it = test.begin(); it != test.end();){ if (*it != 2) it++; else it=test.erase(it);//erase會銷毀迭代器,並更新迭代器的值 } test.push_back(INT_MAX); test.push_front(INT_MIN); test.pop_back(); test.pop_front(); test.erase(remove(test.begin(), test.end(), 1), test.end());//remove非成員函數,並不能真正刪除,只是把要刪除的數據扔到后面並返回尾迭代器的值 //不支持隨機訪問 //cout << test[0] << endl; //查找 if (find(test.begin(), test.end(), 3) != test.end()) cout << "find it" << endl; //反轉 reverse(test.begin(), test.end()); return 0; }