且构网

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

在C中将链接列表实现为光标链接列表

更新时间:2021-06-30 01:40:10

最简单的方法是将链接指针替换为int索引,然后在通常访问该指针时跟随该索引. br/>
您将一个空闲节点列表用作列表的零元素-因此您可能需要将空间增加一,否则您将只能为100个元素的数组存储99个节点.希望您的MakeEmpty函数可以设置所有可用的指针!

从链接列表代码开始,并通过用索引访问替换指针进行工作-如果正确编写了MakeEmpty,这应该是一个非常简单的转换.
The easy way is to just replace your link pointers with int indexes - and then follow the index when you would normally access the pointer.

You are using a free node list as element zero of your list - so you will probably need to increase the space by one, or you will only be able to store 99 nodes for a 100 element array. Hopefully, your MakeEmpty function sets up all the free pointers!

Start with your linked list code, and work through replacing pointers with indexed accesses - it should be a pretty easy conversion if you have written MakeEmpty correctly.