Basic Linked List Operations
This lesson lists the various operations that can be performed on linked lists.
We'll cover the following
Introduction
The primary operations that generally form a part of the LinkedList
class are listed below:
insertAtTail(data)
- inserts an element at the end of the linked listinsertAtHead(data)
- inserts an element at the start/head of the linked listdelete(data)
- deletes an element with your specified value from the linked listdeleteAtHead()
- deletes the first element of the listsearch(data)
- searches for an element in the linked listisEmpty()
- returns true if the linked list is empty
isEmpty()
is a helper function that will be useful in the implementation of other functions.
So, let’s define it first.
isEmpty()
The basic condition for our list to be considered empty is that the head points to null
. This essentially means there is no node in the linked list.
With that in mind, let’s write down the simple implementation for isEmpty()
:
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.