【发布时间】:2018-12-27 20:20:22
【问题描述】:
本题中,静态链表定义如下:(c++代码)
template<typename T> struct Node{
T elem;
int next;//yes, int, which points to the index of the next element in the array.
};
Node static_linked_list [SOME_SIZE];
//some initialization code omitted.
所以在这种链表中,它是静态的,因为它的大小是在数组初始化期间分配的。链接是通过字段int next 实现的,该字段指向下一个元素的索引。
与基于指针(或引用)的链表相比,这种数据结构有什么优势?它的应用是什么?据我所知,静态的有作用域生命周期,可以在实现malloc 时使用。但是它的int next 的内存消耗似乎并不比指针少。
【问题讨论】:
标签: data-structures linked-list