Skip to content

Instantly share code, notes, and snippets.

@ilmanzo
Last active May 25, 2020 08:59
Show Gist options
  • Save ilmanzo/8ed9bb4aa511391ac4802ef9376266b1 to your computer and use it in GitHub Desktop.
Save ilmanzo/8ed9bb4aa511391ac4802ef9376266b1 to your computer and use it in GitHub Desktop.
module main
struct List {
head &Node
name string
}
struct Node {
mut: data int
next &Node
}
fn new_list(listname string) &List {
return &List{name: listname, head: none }
}
fn (mut l List) append(newdata int) {
if l.head == none {
l.head= &Node{data: newdata, next: none}
return
}
mut n:=l.head
for {
if n.next != none { n=n.next } else { break }
}
n.next=&Node{data: newdata, next: none}
}
fn (l List) print() {
mut n:=l.head
for {
print(n.data)
if n.next != none { n=n.next } else { break }
}
}
fn main() {
l:=new_list("test")
l.append(1)
l.print()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment