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
956 B

6 years ago
## listpushback
6 years ago
### Instructions
Write a function `ListAt` that haves one pointer to the list, `l`, and an `int` as parameters. This function should print a `Node` of the linked list, depending on the number, `nbr`.
- In case of error it should print `nil`
6 years ago
### Expected function and structure
```go
type Node struct {
Data interface{}
Next *Node
}
func ListAt(l *Node, nbr int) *Node{
}
```
6 years ago
### Usage
Here is a possible [program](TODO-LINK) to test your function :
```go
package main
import (
"fmt"
piscine ".."
)
func main() {
link := &Node{}
ListPushBack(link, "hello")
ListPushBack(link, "how are")
ListPushBack(link, "you")
ListPushBack(link, 1)
fmt.Println()
fmt.Println(ListAt(link, 3).Data)
fmt.Println(ListAt(link, 1).Data)
fmt.Println(ListAt(link, 7))
}
```
And its output :
```console
student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test
you
hello
<nil>
student@ubuntu:~/piscine/test$
```