且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不使用指针的链表实现是否可行?

更新时间:2022-03-24 22:33:21

当然,如果你不介意链表有一个最大大小,你可以静态分配一个链表节点数组,然后使用整数索引到数组作为每个节点的上一个"和下一个"值,而不是指针.我过去这样做是为了节省一点内存(因为整数可以是 2 或 4 个字节,而在 64 位系统上,指针将是 8 个字节)

Sure, if you don't mind the linked list having a maximum size, you could statically allocate an array of list nodes, and then use integer indices into the array as your "previous" and "next" values for each node, rather than pointers. I've done in this in the past to save a bit of memory (since an integer can be either 2 or 4 bytes, whereas on a 64-bit system a pointer will be 8 bytes)