Basic Linked List Operations

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

Operations #

Following are the basic operations of a Singly Linked List:

Operations Descriptions
insertAtEnd(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 from the linked list
deleteAtHead() Deletes the first element of the list
deleteAtEnd() Deletes the last element of the list
Search(data) Searches an element from the linked list
isEmpty() Returns True if the linked list is empty, otherwise returns False

If you observe the list of methods mentioned above, the last function, isEmpty() is a helper function which will prove useful in defining all the other functions.

So let’s define it first.

isEmpty() #

The basic condition for our list to be considered empty is that the head should be the only pointer in the list. This implies that the head points to NULL.

With that in mind, let’s write down the simple implementation for isEmpty():

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.