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.

70 lines
1.1 KiB

## listfind
6 years ago
### Instructions
Write a function `ListFind` that returns the address of the first node in the list `l` that is determined to be equal to `ref` by the function `CompStr`.
- For this exercise the function `CompStr` must be used.
6 years ago
### Expected function and structure
```go
type NodeL struct {
Data interface{}
Next *NodeL
}
type List struct {
Head *NodeL
Tail *NodeL
}
func CompStr(a, b interface{}) bool {
return a == b
}
func ListFind(l *List, ref interface{}, comp func(a, b interface{}) bool) *interface{} {
}
```
6 years ago
### Usage
Here is a possible program to test your function :
```go
package main
import (
"fmt"
piscine ".."
)
func main() {
link := &piscine.List{}
piscine.ListPushBack(link, "hello")
piscine.ListPushBack(link, "hello1")
piscine.ListPushBack(link, "hello2")
piscine.ListPushBack(link, "hello3")
found := piscine.ListFind(link, interface{}("hello2"), piscine.CompStr)
fmt.Println(found)
fmt.Println(*found)
}
```
And its output :
```console
$ go run .
0xc42000a0a0
hello2
$
```
### Note
5 years ago
- The address may be different in each execution of the program.