c++ - 链表语法 : is "next" already defined?

标签 c++ pointers data-structures linked-list definition

我是数据结构方面的新手。 当我尝试使用 C++ 使用链表编写代码时,我想到了一个问题。

在链表中,指针next,previous是由编译器定义的吗?或者我们必须自己命名,而我们如何调用它并不重要?

最佳答案

nextprevious 不是预定义的。我们必须自己定义它。通常对于单链表,我们会想出一个节点结构,它由一个数据字段和一个next指针组成,该指针是指向同一类型节点的指针。一个简单的例子如下:

struct node{
   int data;     //data part
   struct node *next;    // next pointer - points to a node of the same type
}

关于c++ - 链表语法 : is "next" already defined?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19673929/

相关文章:

c++ - 用于搜索数字和字符串的高效数据结构

C++ 只读取文件中的随机行

c++ - C++ 中 const 指针可变

c - 来自不兼容指针类型警告的初始化

c++ - 使用 std::map::at 时出错

c - 正确返回指针

algorithm - 编程: Give the count of all such numbers which have 3 in their decimal representation

c++ - 从 C/C++ 创建和删除文件

c++ - C++ 表达式什么时候格式正确?

C++ 为什么要使用公共(public)、私有(private)或保护继承?