dtelenkov преди 3 седмици
родител
ревизия
26b2e0273e
променени са 1 файла, в които са добавени 25 реда и са изтрити 1 реда
  1. 25 1
      go/stepik/4/list.go

+ 25 - 1
go/stepik/4/list.go

@@ -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))
+
+}