Is a Linked-List implementation without using pointers possible or not?

前端 未结 14 1545
再見小時候
再見小時候 2020-12-01 07:57

My question is very simple, can one using C++, implement a link-list data structure without using pointers (next nodes)? To further qualify my question, I\'m mean can one cr

相关标签:
14条回答
  • 2020-12-01 08:54

    Yes, it's possible. Use array indexes instead of pointers.

    0 讨论(0)
  • 2020-12-01 08:54

    From Wikipedia:

    In computer science, a linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next record in the sequence.

    Nothing in that definition specifies the manner in which the reference is stored or used. If you don't store a reference, it isn't a linked list -- it's something else.

    If your goal is merely to avoid using a pointer (or object reference), then using a vector with an index is a common implementation. (One of the reasons for using the vector/index implementation is persistence: it's really hard to correctly persist pointers / object references outside of the active memory space.)

    0 讨论(0)
提交回复
热议问题