Linked List Attempt

Run Settings
LanguageNim
Language Version
Run Command
type Node = ref object of RootObj prev, next: Node data: string List = ref object of RootObj starting, ending: Node count: int proc addItem( list: List, val: string ): int = if list.count == 0: list.starting = Node( prev: nil, next: nil, data: val ) list.starting.data = val list.ending = list.starting else: list.ending.next = Node( prev: nil, next: nil, data: val ) list.ending.next.prev = list.ending list.ending = list.ending.next list.count += 1 result = list.count iterator items( list: List ): string = var itr = list.starting while itr != nil: yield itr.data itr = itr.next if isMainModule: var list: List = List( starting: nil, ending: nil, count: 0 ) echo addItem( list, "hello" ) echo addItem( list, "world" ) for item in list: echo item
Editor Settings
Theme
Key bindings
Full width
Lines