Basic Linked List Operations
This lesson lists the various operations that can be performed on linked lists
We'll cover the following
The primary operations, which are generally 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 listGetHead()
- Returns head of the linked listIsEmpty()
- Returns true if the linked list is empty
If you observe the list of functions mentioned above, the last function, IsEmpty()
is a helper function, which will prove useful in defining all the other functions.
Let’s define it first.
IsEmpty()
The basic condition for your list to be considered empty is that the head should be the only pointer in the list. This implies that the head should point to null
.
With that in mind, write down the simple implementation for isEmpty()
:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.