如果将其添加为全局结构,则如何将其添加为NULL
How do you add a value to a global struct if it is initialized as NULL?
通常,我只会在main中输入 head = new Node
,这将设置所有内容,但规定是我无权与全局变量混乱。这是我只能访问MAIN的任务,并且由于其他后端功能,我必须完整地将全局变量留下,以便我无法用head = new Node
覆盖它。
重点只是将字符添加到链接列表中。我只是用硬编码为例,但我仍然无法避免错误。
是否有正确的添加方法?
struct Node{
char key;
Node *next;
};
Node *head = NULL;
int main(){
char x = 'a';
cout<<x<<endl;
head->key=x;
}
分配:在给定值范围之间找到BST中的所有节点。然后构建值的链接列表,列表应按上升顺序。
注意:链接列表的头部在后端在全球声明,其初始值为null。只需使用头部将节点添加到链接列表中。链接列表的打印也将在后端进行。可以使用辅助功能。
void rangesearch(treenode *node,char m,char n);
头只是指向NULL的指针。没有为节点分配的真实对象/内存。您首先要为其分配内存。
在您的作业中,您可以并且应该(据我所知)将节点添加到链接列表中,因此您必须分配新节点。
struct Node {
char key;
Node *next;
};
Node *head = NULL;
int main() {
char x = 'a';
head = new Node();
cout << x << endl;
head->key = x;
delete head;
return 0;
}
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 如何在C++中从两个单独的for循环中添加两个数组
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 如何仅为一个函数添加延迟
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 使用std::transform将一个范围的元素添加到另一个范围中
- 如何将更多文件夹添加到c++include路径
- 如何将元素添加到数组的线程安全函数?
- QT通过C++添加映射QML项目
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 如果我std::dynamic_pointer_cast并且底层dynamic_cast的结果为null,那么返回的sh
- 添加 NULL 以终止双指针
- 如果将其添加为全局结构,则如何将其添加为NULL
- 为 fstream 添加 NULL 终止符
- cin函数是否添加了在输入结束时终止的null
- 将添加到队列的第一个元素作为 null 进行排序
- 添加到链表的节点在函数后恢复为 NULL
- 添加printf语句时,NULL指针异常消失
- 如何将变量添加到以null结尾的wchar_t字符串中
- boost::transform() 仅当添加的值不是 NULL 时?