如何在c++中创建节点

How to create nodes in c++?

本文关键字:创建 节点 c++      更新时间:2023-10-16

编写一个函数,将节点插入链表的头部。该函数接受两个参数:指向双链接列表中第一个节点的指针和字符串值。它应该创建一个具有给定值的新节点到双链接列表的头部。

这是我需要回答的问题。我不是在寻找答案,我只是不确定如何在C++中创建一个节点。

这应该是您想要的。

struct node{
node * next;
std::string value;
};
node * addToTheFront(node * front, std::string value){
node * temp = new node;
temp->next = front;
temp->value = value;
return temp;
}