mirror of https://github.com/01-edu/public.git
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.
62 lines
897 B
62 lines
897 B
5 years ago
|
## listpushback
|
||
5 years ago
|
|
||
5 years ago
|
### Instructions
|
||
5 years ago
|
|
||
![]()
5 years ago
|
Write a function `ListPushBack` that inserts a new element `NodeL` at the end of the list `l` while using the structure `List`.
|
||
5 years ago
|
|
||
5 years ago
|
### Expected function and structure
|
||
5 years ago
|
|
||
|
```go
|
||
![]()
5 years ago
|
type NodeL struct {
|
||
5 years ago
|
Data interface{}
|
||
![]()
5 years ago
|
Next *NodeL
|
||
5 years ago
|
}
|
||
|
|
||
|
type List struct {
|
||
![]()
5 years ago
|
Head *NodeL
|
||
|
Tail *NodeL
|
||
5 years ago
|
}
|
||
|
|
||
|
func ListPushBack(l *List, data interface{}) {
|
||
![]()
5 years ago
|
|
||
5 years ago
|
}
|
||
|
```
|
||
|
|
||
5 years ago
|
### Usage
|
||
5 years ago
|
|
||
5 years ago
|
Here is a possible program to test your function :
|
||
5 years ago
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
piscine ".."
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
|
||
![]()
5 years ago
|
link := &piscine.List{}
|
||
5 years ago
|
|
||
|
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
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$ go build
|
||
|
student@ubuntu:~/[[ROOT]]/test$ ./test
|
||
5 years ago
|
Hello
|
||
|
man
|
||
|
how are you
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$
|
||
5 years ago
|
```
|