Browse Source

readme listmerge sintaxe problems and fixing the function

content-update
lee 5 years ago
parent
commit
92f7be598f
  1. 42
      subjects/listmerge.en.md

42
subjects/listmerge.en.md

@ -1,4 +1,4 @@
## listpushback ## listmerge
### Instructions ### Instructions
@ -6,22 +6,20 @@ Write a function `ListMerge` that places elements of a list `l2` at the end of a
- You can't create new elements! - You can't create new elements!
- Use pointers when 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 ListMerge(l1 *list, l2 *list) { func ListMerge(l1 *List, l2 *List) {
} }
``` ```
@ -35,34 +33,38 @@ 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(nil, "\n")
fmt.Print(l.tail)
fmt.Println()
} }
func main() { func main() {
link := &list{} link := &piscine.List{}
link2 := &list{} link2 := &piscine.List{}
piscine.ListPushBack(link, "a") piscine.ListPushBack(link, "a")
piscine.ListPushBack(link, "b") piscine.ListPushBack(link, "b")
piscine.ListPushBack(link, "c") piscine.ListPushBack(link, "c")
piscine.ListPushBack(link, "d") piscine.ListPushBack(link, "d")
fmt.Println("-----first List------")
PrintList(link)
piscine.ListPushBack(link2, "e") piscine.ListPushBack(link2, "e")
piscine.ListPushBack(link2, "f") piscine.ListPushBack(link2, "f")
piscine.ListPushBack(link2, "g") piscine.ListPushBack(link2, "g")
piscine.ListPushBack(link2, "h") piscine.ListPushBack(link2, "h")
fmt.Println("-----second List------")
PrintList(link2)
fmt.Println("-----Merged List-----")
piscine.ListMerge(link, link2) piscine.ListMerge(link, link2)
PrintList(link) PrintList(link)
} }

Loading…
Cancel
Save