how to implement doubly linked lists

后端 未结 3 2065
夕颜
夕颜 2020-12-05 02:54

Is it possible to have a doubly linked list in Haskell, and what\'s the ideal solution to implementing them? I\'m implementing a scene graph where every widget has a parent

3条回答
  •  生来不讨喜
    2020-12-05 03:27

    A doubly linked list is not a data type but an implementation detail. What I presume you want is a list-like data structure where you can move both left and right, efficiently. This data structure is the zipper of a list and is simply a pair of lists. The prefix is represented in reversed order. To move left/right you simply shift the head of the postfix list onto the prefix, and vice versa.

提交回复
热议问题