Skip to content

Conversation

@sammychien
Copy link

The GetLast() function traverses through the entire LL to get to the last pointer, when there's already a tail node. The fix gets rid of the traversal and returns the tail node value.

func (list *LinkedList) GetLast() (int, bool) {
	if list.head == nil {
		return 0, false
	}
	return list.tail.data, true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant