|
|
@@ -9,12 +9,15 @@ func printList(l *list.List) {
|
|
|
for temp := l.Front(); temp != nil; temp = temp.Next() {
|
|
|
fmt.Printf("%v ", temp.Value)
|
|
|
}
|
|
|
+ fmt.Println()
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
// foo1()
|
|
|
- foo2()
|
|
|
+ // foo2()
|
|
|
+ foo3()
|
|
|
|
|
|
/*
|
|
|
mylist := list.New()
|
|
|
@@ -104,3 +107,24 @@ func printQueue(queue *list.List) {
|
|
|
fmt.Print(temp.Value)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// ---------------------------------------------------------------
|
|
|
+
|
|
|
+func ReverseList(l *list.List) *list.List {
|
|
|
+ reversedList := list.New()
|
|
|
+ for temp := l.Front(); temp != nil; temp = temp.Next() {
|
|
|
+ reversedList.PushFront(temp.Value)
|
|
|
+ }
|
|
|
+ return reversedList
|
|
|
+}
|
|
|
+
|
|
|
+func foo3() {
|
|
|
+ mylist := list.New()
|
|
|
+ for i := 0; i < 10; i++ {
|
|
|
+ mylist.PushBack(i)
|
|
|
+ }
|
|
|
+
|
|
|
+ printList(mylist)
|
|
|
+ printList(ReverseList(mylist))
|
|
|
+
|
|
|
+}
|