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

前端 未结 14 1548
再見小時候
再見小時候 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:43

    Wow, NO? Surely you guys are not serious?

    All a linked list needs is a link. Nothing says it has to be a pointer. Consider the case of wanting to store a linked list in shared mem, where the base addr is dynamic? Answer is simply, store the link as a Offset from the start of the mem block, (or some other constant) and redefine the iterator to do the actual logic of adding the base addr. Obviously, insert etc would have to be changed as well.

    But fairly trivial!

    Allan

提交回复
热议问题