Browse Source

Merge pull request #234 from 01-edu/fix-listremoveif

fixing the main and some sintax errors
content-update
augusto-mantilla 5 years ago committed by GitHub
parent
commit
199af48a7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      subjects/listremoveif.en.md

46
subjects/listremoveif.en.md

@ -4,24 +4,20 @@
Write a function `ListRemoveIf` that removes all elements that are equal to the `data_ref` introduced in the argument of the function. Write a function `ListRemoveIf` that removes all elements that are equal to the `data_ref` introduced in the argument of the function.
- In case the list is empty print the message `no data on list`.
- Use pointers wen ever you can.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { type NodeL struct {
data interface{} data interface{}
next *node next *NodeL
} }
type list struct { type List struct {
head *node Head *NodeL
tail *node Tail *NodeL
} }
func ListRemoveIf(l *list, data_ref interface{}) { func ListRemoveIf(l *List, data_ref interface{}) {
} }
``` ```
@ -35,33 +31,28 @@ package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
func PrintList(l *list) { func PrintList(l *piscine.List) {
m := l.head it := l.Head
for m != nil { for it != nil {
fmt.Print(m.data, " -> ") fmt.Print(it.Data, " -> ")
m = m.next it = it.Next
} }
fmt.Print(l.tail) fmt.Print(nil, "\n")
fmt.Println()
} }
func main() { func main() {
link := &list{} link := &piscine.List{}
link2 := &list{} link2 := &piscine.List{}
link3 := &list{}
fmt.Println("------answer-----")
ListRemoveIf(link3, 1)
fmt.Println()
fmt.Println("----normal state----") fmt.Println("----normal state----")
piscine.ListPushBack(link2, 1) piscine.ListPushBack(link2, 1)
PrintList(link2) PrintList(link2)
ListRemoveIf(link2, 1) piscine.ListRemoveIf(link2, 1)
fmt.Println("------answer-----") fmt.Println("------answer-----")
PrintList(link) PrintList(link)
fmt.Println() fmt.Println()
@ -80,7 +71,7 @@ func main() {
piscine.ListPushBack(link, 1) piscine.ListPushBack(link, 1)
PrintList(link) PrintList(link)
ListRemoveIf(link, 1) piscine.ListRemoveIf(link, 1)
fmt.Println("------answer-----") fmt.Println("------answer-----")
PrintList(link) PrintList(link)
} }
@ -92,9 +83,6 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
------answer-----
no data on list
----normal state---- ----normal state----
1 -> <nil> 1 -> <nil>
------answer----- ------answer-----

Loading…
Cancel
Save