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.

71 lines
1.2 KiB

## listfind
5 years ago
### Instructions
Écrire une fonction `ListFind` qui retourne l'adresse de la première node dans la liste `l` qui est déterminée comme étant égale à `ref` par la fonction `CompStr`.
- Pour cet exercice la fonction `CompStr` doit être utilisée.
### Fonction et structure attendues
```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{} {
}
```
5 years ago
### Utilisation
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction :
```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)
}
```
Et son résultat :
```console
student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test
0xc42000a0a0
hello2
student@ubuntu:~/piscine/test$
```
### Note
- L'addresse peut être différente à chaque exécution du programme.