带有矢量指针的链接列表

Link list with a vector pointer

本文关键字:链接 列表 指针      更新时间:2023-10-16

我正试图使用向量结构来连接节点,为我的数据结构课程构建一个树。这是我的密码。

#include<iostream>
#include<string>
#include<vector>
using namespace std;
struct node
{
    vector<node> *next;
    string val;
    int tagid;
};
int main()
{
    string operation;
    node *head=new node;
    head->next->resize(1);
    return 0;
}

现在我尝试用以下代码修改第一个元素的指针

head->next[0]=NULL;

编译器给了我错误no match for ‘operator=’。我如何才能正确地编写它以修改它的元素?

根据@Zaiborg的评论,这对我来说很有效:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct node {
    vector<node*> next;
    string val;
    int tagid;
};
int main()
{
    string operation;
    node *head = new node;
    head->next.resize(1);
    head->next[0] = NULL;
    return 0;
}

使用:g++编译-Wall在编译时不会给您任何警告和错误。