Linked list with struct, recursive data structure with UnsafeMutablePointer

时间:2015-07-31 19:32:55

标签: swift struct linked-list swift2 recursive-datastructures

I tried to create a linked list with struct (I know it can be done with enums or classes), and here is my attempt:

struct LinkedListStruct<T> {

    let head: T
    var tail: UnsafeMutablePointer<LinkedListStruct<T>>
}

it compiles fine, but when I try to use it in a very simple way:

let list = LinkedListStruct(head: 1, tail: nil)

print("End")

"End" will never be printed out to the console. At the debug navigator view, the cpu usage is at 0% and the memory is not increasing, so I assume that it is not due to recursion. What's wrong with this implementation?

0 个答案:

没有答案