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:
get_head()
- returns the head of the listinsert_at_tail(data)
- inserts an element at the end of the linked listinsert_at_head(data)
- inserts an element at the start/head of the linked listdelete(data)
- deletes an element with your specified value from the linked listdelete_at_head()
- deletes the first element of the listsearch(data)
- searches for an element with the specified value in the linked listis_empty()
- returns true if the linked list is empty
If you observe the list of functions mentioned above, get_head()
and is_empty()
are helper functions that will prove useful in all the others.
So let’s define them first.
get_head()
This method simply returns the head node of our linked list:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.