|
|
@ -9,17 +9,17 @@ Write a function `ListReverse` that reverses the elements order of a given linke |
|
|
|
### 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 ListReverse(l *list) { |
|
|
|
func ListReverse(l *List) { |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
@ -36,18 +36,18 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
link := &list{} |
|
|
|
link := &piscine.List{} |
|
|
|
|
|
|
|
|
|
|
|
listPushBack(link, 1) |
|
|
|
piscine.ListPushBack(link, 1) |
|
|
|
listPushBack(link, 2) |
|
|
|
piscine.ListPushBack(link, 2) |
|
|
|
listPushBack(link, 3) |
|
|
|
piscine.ListPushBack(link, 3) |
|
|
|
listPushBack(link, 4) |
|
|
|
piscine.ListPushBack(link, 4) |
|
|
|
|
|
|
|
|
|
|
|
listReverse(link) |
|
|
|
piscine.ListReverse(link) |
|
|
|
|
|
|
|
|
|
|
|
for link.head != nil { |
|
|
|
for link.Head != nil { |
|
|
|
fmt.Println(link.head.data) |
|
|
|
fmt.Println(link.Head.Data) |
|
|
|
link.head = link.head.next |
|
|
|
link.Head = link.Head.Next |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|