Basic Linked List Operations

This lesson lists the various operations that can be performed on linked lists

The primary operations which are generally a part of the LinkedList class are listed below:

  • get_head() - returns the head of the list
  • insert_at_tail(data) - inserts an element at the end of the linked list
  • insert_at_head(data) - inserts an element at the start/head of the linked list
  • delete(data) - deletes an element with your specified value from the linked list
  • delete_at_head() - deletes the first element of the list
  • search(data) - searches for an element with the specified value in the linked list
  • is_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.