结构之外的节点 * head 有什么作用?
What does Node * head outside of the struct do?
所以我有类LinkedList。有人可以解释为什么节点 * head 在结构体之外,节点 * 下一个,上一个在结构体内部吗?这样做的目的是什么,它与其他目的有何不同?谢谢
class LinkedList
{
public:
LinkedList();
~LinkedList();
void add(char ch);
bool find(char ch);
bool del(char ch);
void display(
private:
struct node
{
char data;
node * next;
node * prev;
};
node *head;
};
struct node
{
char data;
node * next;
node * prev;
};
是类中结构类型的内部声明。
这
node *head;
是类LinkedList
的类型struct node *
的数据成员的声明。为了使其更清晰,请按以下方式重写列表定义
struct node
{
char data;
node * next;
node * prev;
};
class LinkedList
{
public:
LinkedList();
~LinkedList();
void add(char ch);
bool find(char ch);
bool del(char ch);
void display(
private:
node *head;
};
将类定义中的结构声明为私有声明会使结构类型对链表的用户不可见。
相关文章:
- archive_read_support_filter_all() 有什么作用?
- 当我们为(;;) 写作时,它做了什么?for 循环中的双分号有什么作用?
- 这个递归函数有什么作用?运行时的复杂性是多少?
- DrawShadow 中的 Elevation 究竟有什么作用?
- 测试"stream >> char"有什么作用?
- "uFlags &= ~CHN_PANNING"命令有什么作用?
- GCC 的 -Wpsabi 选项究竟有什么作用?压制它意味着什么?
- int** a = new int*[n]();这个函数有什么作用?
- C++ 此函数调用之前的(void)有什么作用?
- i+=(i&-i) 有什么作用?它是便携式的吗?
- 这个size_t在 lambda 中有什么作用?C++代码
- 数组下标运算符 ([ ]) 对数组有什么作用?
- 结构之外的节点 * head 有什么作用?
- 重载括号运算符有什么作用?
- clang的"-Ofast"选项在实践中有什么作用,特别是对于与gcc的任何差异?
- std::make_unique_for_overwrite() 对 std::make_unique() 有什么作用?
- 运算符 delete[] 有什么作用?
- 下面的代码有什么作用?c++
- 这个陈述'p = I.ptr<uchar>(i);有什么作用?
- 这个嵌套的名称空间定义有什么作用