Skip to content

Commit b1dd26d

Browse files
committed
Reversed Linked List Implementation
1 parent 11d38bb commit b1dd26d

File tree

2 files changed

+31
-173
lines changed

2 files changed

+31
-173
lines changed

linkedList/LinkedList.go

Lines changed: 0 additions & 173 deletions
This file was deleted.

linkedList/reverseLinkedList.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Reverse a linked list in both iterative and recursive way
3+
*/
4+
5+
// The code for reversing a linkedlist is in the linkedlist package
6+
// Refer to the package for implementation
7+
8+
package main
9+
10+
import ("fmt"
11+
"AlgorithmsGolang/linkedList/LinkedList"
12+
)
13+
14+
func main() {
15+
ll := LinkedList.New()
16+
ll.PushBack(5)
17+
ll.PushBack(10)
18+
ll.PushBack(20)
19+
ll.PushBack(50)
20+
ll.PushBack(100)
21+
ll.PushFront(500)
22+
23+
e := ll.Front()
24+
fmt.Println("Recursive Method")
25+
ll.ReversedRecursive(e) // Should Print 100,50,20,10,5,500
26+
ll.Print()
27+
fmt.Println("----")
28+
fmt.Println("Iterative Method - Reverses the reversed linked list, should return the original linkedlist")
29+
ll.ReversedIterative() // Should Print 500,5,10,20,50,100
30+
ll.Print()
31+
}

0 commit comments

Comments
 (0)