Skip to content

Commit

Permalink
[#16] add: LinkedList::Front
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Oct 3, 2023
1 parent 646d7d3 commit da18976
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions linked_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ func (list *LinkedList[T]) PopFront() Option[T] {
return Some[T](value)
}

// Provides a reference to the front element, or None if the list is empty.
// This operation should compute in O(1) time.
func (list *LinkedList[T]) Front() Option[*T] {
if list.head == nil {
return None[*T]()
}

return Some[*T](&list.head.value)
}

// into_iter
func (list *LinkedList[T]) IntoIter() Iterator[T] {
return &LinkedListIter[T]{
Expand Down

0 comments on commit da18976

Please sign in to comment.