1. vector的操作
    添加元素:
    向尾部添加一个元素
vector<int> a;
a.push_back(1);

向尾部添加多个元素
-向尾部添加x个同样的元素:

a.insert(a.end(),5,1);

从某个位置插入

a.insert(a.begin()+1,5);

删除元素:

a.erase(a.begin()+2);

vector的迭代器/vector的按序输出:

for(vector<int>::iterator it = a.begin();it!=a.end(); it++)
    {
        cout << *it <<endl;
    }
  1. ListNode
    是一个数据类型,定义:
struct ListNode
{
    int val; //当前节点的值
    ListNode* next; //指向下一个节点的指针
    //初始化构造函数,与结构体同名的定义函数,特殊的成员函数
    ListNode(int x): val(x), next(NULL){}
};

相关文章:

  • 2021-11-24
  • 2021-08-06
  • 2021-07-11
  • 2021-11-18
  • 2021-08-19
  • 2021-11-15
  • 2022-02-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2021-07-03
  • 2021-09-05
  • 2021-08-13
  • 2021-11-01
相关资源
相似解决方案