MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Reverse

Method Reverse

structure/linkedlist/singlylinkedlist.go:127–139  ·  view source on GitHub ↗

Reverse reverses the list.

()

Source from the content-addressed store, hash-verified

125
126// Reverse reverses the list.
127func (ll *Singly[T]) Reverse() {
128 var prev, next *Node[T]
129 cur := ll.Head
130
131 for cur != nil {
132 next = cur.Next
133 cur.Next = prev
134 prev = cur
135 cur = next
136 }
137
138 ll.Head = prev
139}
140
141// ReversePartition Reverse the linked list from the ath to the bth node
142func (ll *Singly[T]) ReversePartition(left, right int) error {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected