Basic Linked List Operations

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

We'll cover the following

Introduction

The primary operations that generally form 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
  • isEmpty() - returns true if the linked list is empty

isEmpty() is a helper function that will be useful in the implementation of other functions.

So, let’s define it first.

isEmpty()

The basic condition for our list to be considered empty is that the head points to null. This essentially means there is no node in the linked list.

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.