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.
57 lines
792 B
57 lines
792 B
5 years ago
|
## listsize
|
||
6 years ago
|
|
||
6 years ago
|
### Instructions
|
||
6 years ago
|
|
||
5 years ago
|
Write a function `ListSize` that returns the number of elements in a linked list `l`.
|
||
6 years ago
|
|
||
6 years ago
|
### Expected function and structure
|
||
6 years ago
|
|
||
|
```go
|
||
5 years ago
|
type NodeL struct {
|
||
6 years ago
|
Data interface{}
|
||
5 years ago
|
Next *NodeL
|
||
6 years ago
|
}
|
||
|
|
||
|
type List struct {
|
||
5 years ago
|
Head *NodeL
|
||
|
Tail *NodeL
|
||
6 years ago
|
}
|
||
|
|
||
|
func ListSize(l *List) int {
|
||
|
|
||
|
}
|
||
|
```
|
||
|
|
||
6 years ago
|
### Usage
|
||
6 years ago
|
|
||
5 years ago
|
Here is a possible program to test your function :
|
||
6 years ago
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
piscine ".."
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
5 years ago
|
link := &piscine.List{}
|
||
6 years ago
|
|
||
|
piscine.ListPushFront(link, "Hello")
|
||
|
piscine.ListPushFront(link, "2")
|
||
|
piscine.ListPushFront(link, "you")
|
||
|
piscine.ListPushFront(link, "man")
|
||
|
|
||
|
fmt.Println(piscine.ListSize(link))
|
||
|
}
|
||
|
```
|
||
|
|
||
|
And its output :
|
||
|
|
||
|
```console
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$ go build
|
||
|
student@ubuntu:~/[[ROOT]]/test$ ./test
|
||
6 years ago
|
4
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$
|
||
6 years ago
|
```
|