list双向链表

  1. // 双向链表的执行效率比较慢,一般不用这个
  2. // 大纲里出现的,介绍一下
  3. #include <list>
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6. list<int> lst;
  7. void print(){
  8. for (auto x : lst) cout << x << ' ';
  9. puts("");
  10. }
  11. int main(){
  12. lst.push_back(1);
  13. lst.push_back(2);
  14. lst.push_back(3);
  15. print(); //1 2 3
  16. lst.push_front(4);
  17. lst.push_front(5);
  18. lst.push_front(6);
  19. print(); //6 5 4 1 2 3
  20. lst.pop_back();
  21. print(); //6 5 4 1 2
  22. lst.pop_front();
  23. print(); //5 4 1 2
  24. return 0;
  25. }
  26. /*
  27. 输出
  28. 1 2 3
  29. 6 5 4 1 2 3
  30. 6 5 4 1 2
  31. 5 4 1 2
  32. */