Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <[email protected]>
  • Loading branch information
cody-littley committed Nov 25, 2024
1 parent 9100eac commit 71a5aaa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions common/queue/linked_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ type node[T any] struct {
}

func (l *LinkedQueue[T]) Push(value T) {
newNode := &node[T]{value: value}
if l.size == 0 {
l.front = &node[T]{value: value}
l.front = newNode
l.back = l.front
} else {
n := &node[T]{value: value}
l.back.next = n
l.back = n
l.back.next = newNode
l.back = newNode
}
l.size++
}
Expand All @@ -36,6 +36,10 @@ func (l *LinkedQueue[T]) Pop() (T, bool) {
value := l.front.value
l.front = l.front.next
l.size--

if l.size == 0 {
l.back = nil
}
return value, true
}

Expand Down

0 comments on commit 71a5aaa

Please sign in to comment.