我是C编程的新手,我正在用C学习C算法.
这是我关于如何定义二叉树node数据结构的问题.
以下是用于定义Node数据结构的2个典型示例代码.
typedef struct binaryTreeNode_{
int key;
void *data;
binaryTreeNode_ *leftNode;
binaryTreeNode_ *rightNode;
} binaryTreeNode;
Run Code Online (Sandbox Code Playgroud)
typedef struct binaryTreeNode_{
int key;
void *data;
binaryTreeNode_ *leftNode;
binaryTreeNode_ *rightNode;
binaryTreeNode_ *parentNode;
} binaryTreeNode;
Run Code Online (Sandbox Code Playgroud)
显然,使用具有父节点指针的节点结构将使更多工作变得更加容易.像遍历节点/树,DFS/BFS与二叉树.所以我的问题是为什么有些解决方案基于没有父节点的结构?.
有历史原因吗?如果仅仅因为RAM/DISK容量的限制,我想我们可以放弃没有父节点的解决方案,不是吗?
就像链表和双向链表,我们应该使用双链表来实现Stack和Queue?