1

This question already has an answer here:

In any language, I would write following:

struct Node {
   void* data;
   Node* next;
}

...

head.next = new Node(data, null)

But it seems that solidity doesn't have a concept of pointers.

How could it be done here?

EDIT The answer at the end of Are there well-solved and simple storage patterns for Solidity? is not enough for me as I also need to insert nodes to the middle.

marked as duplicate by Richard Horrocks, Meshugah - Bank Of Hodlers, Achala Dissanayake, mirg, Ismael Jun 16 '18 at 3:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • (Linked-lists are mentioned at the end of the accepted answer.) – Richard Horrocks Jun 13 '18 at 17:37
  • I have seen this example, but it doesn't seem to fit to me, because I need to insert in the middle while this code appends only. – Alex Zhukovskiy Jun 13 '18 at 17:42
  • 1
    My blog has an implementation of a doubly linked list: programtheblockchain.com/posts/2018/03/30/…. – smarx Jun 13 '18 at 17:42
  • @smarx thank you for the link. It's seems to be a proper approach. Brb when done. – Alex Zhukovskiy Jun 13 '18 at 18:07
  • 1
    That's the alternative I would have suggested. I'm glad you got it working! – smarx Jun 13 '18 at 19:13
0

Here is a library on GitHub which does the trick for circular doubly linked lists. Although I haven't actually used the library, I referenced it heavily when writing my own similar implementation. Even if you don't use it, there's easily enough to work with to make a simple linked list.

Not the answer you're looking for? Browse other questions tagged or ask your own question.