Linked list implementation with corner cases