NimProgrammingBook
NimProgrammingBook copied to clipboard
The tail insert of linked object
In the chapter of "Reference and Pointers", I'm wondering how can I code the "tail insert" instead of the head insert of linked object? The current example insert item as reverse order.
type
Friend = ref object
name: string
next: Friend
var
f: Friend
node: Friend
n: string
new(f)
node = f
while true:
write(stdout, "Name of friend: ")
n = readline(stdin)
if n=="" or n=="quit":
break
node.next = Friend(name: n)
node = node.next
while f!= nil:
echo f.name
f = f.next