You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
883 B

5 years ago
## listpushback
5 years ago
### Instructions
Write a function `ListPushBack` that inserts a new element `Node` at the end of the list, using the structure `List`
5 years ago
### Expected function and structure
```go
type Node struct {
Data interface{}
Next *Node
}
type List struct {
Head *Node
Tail *Node
}
func ListPushBack(l *List, data interface{}) {
}
```
5 years ago
### Usage
Here is a possible [program](TODO-LINK) to test your function :
```go
package main
import (
"fmt"
piscine ".."
)
func main() {
link := &List{}
piscine.ListPushBack(link, "Hello")
piscine.ListPushBack(link, "man")
piscine.ListPushBack(link, "how are you")
for link.Head != nil {
fmt.Println(link.Head.Data)
link.Head = link.Head.Next
}
}
```
And its output :
```console
student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test
Hello
man
how are you
student@ubuntu:~/piscine/test$
```