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 list
  • InsertAtHead(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
  • DeleteAtHead() - Deletes the first element of the list
  • Search(data) - Searches for an element in the linked list
  • GetHead() - Returns head of the linked list
  • IsEmpty() - 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 70+ hands-on prep courses.