Group Group Group Group Group Group Group Group Group

Doubly-linked, circular, bi-directional linkedList

I am working on a Swift implementation of dancing links algorithm to solve exactCover problems.

I need a linked list (linked matrix actually) that can be navigated in 2-D (left/right, up/down). I am mostly there using the LinkedList class / tutorial proved here - thank you very much.

However, I’m fairly new to Swift and could use some assistance with one final step. I need a way to modify the Collection implementation, or create a new one to return the vertical list like the horizontal one it currently returns. I’d be happy to provide the changes I’ve made to the code, but this forum seems to be the only contact option and I don’t see the ability to upload a file.

My changes are fairly straight-forward:

  1. For my own sanity, I changed next/prev to right/left

  2. I added up/down links

  3. I added the ability for the various iterators to work with circular links

  4. I added SetHead() to initialize a list with the same head as another one because it’s handy to have reference to the list from both directions.

  5. I renamed append(Node) to appendHorizontal(Node)

  6. I added appendVertical(Node)

  7. I modified append() to accept an optional parameter for up/down

  8. I added lastVertical()

It all works and my sparse matrix looks good, but navigating it vertically is cumbersome. So, I’d like to be able to do something like this:

In addition to Navigate Horizontally (as it originally worked):
for hNode in myLinkedList { … }

I’d like to be able to - not sure how to do this
for vNode in myLinkedList(vertical: true) { … } // or something similar

Thanks in advance!

@papavector Do you still have issues with this?