如何在数组中实现链表? [英] How do you implement a linked list within an array?

查看:180
本文介绍了如何在数组中实现链表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题提到有可能去实现数组中的链表。

This question mentions that it is possible to go about implementing a linked list within an array.

虽然我可以想象如何对多个数组进行此操作,但如何对单个数组进行处理呢?

Whilst I can imagine how to do this with multiple arrays, how can it be done with a single array?

编辑:考虑到需要删除的项目,是否可以有效地做到这一点?从列表中插入-大概需要标识数组中的自由元素?

Can this done be efficiently considering that items will need to be removed & inserted from the list - presumably requiring identification of free elements in the array?

推荐答案

您可以(例如)拥有一个链接的-将您的第一个数据项放在数组的元素中,将下一个数据项的索引放在第二个元素中,以获取整数列表。这将限制您存储与索引兼容/可转换为索引的类型。

You could (for example) have a linked-list of integers by putting your first data item in the element of the array, and the index of the next item in the second element. This would restrict you to storing types that were compatible with/convertible to an index.

这篇关于如何在数组中实现链表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆