Skip to content

The tail insert of linked object #25

Description

@geohuz

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        

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions