public class SinglyLinkedList {
// Node class representing each element in the linked list
class Node {
int data;
Node next;
// Constructor to initialize the node with data
Node(int data) {
[Link] = data;
[Link] = null;
// Head node of the linked list
private Node head;
// Constructor to initialize the linked list
public SinglyLinkedList() {
head = null;
// Method to insert a node at the start of the linked list
public void insertAtStart(int data) {
Node newNode = new Node(data);
[Link] = head;
head = newNode;
// Method to insert a node at the end of the linked list
public void insertAtEnd(int data) {
Node newNode = new Node(data);
if (head == null) {
head = newNode;
} else {
Node temp = head;
while ([Link] != null) {
temp = [Link];
[Link] = newNode;
// Method to delete the node at the start of the linked list
public void deleteAtStart() {
if (head == null) {
[Link]("Linked list does not exist");
} else {
head = [Link];
// Method to delete the node at the end of the linked list
public void deleteAtEnd() {
if (head == null) {
[Link]("Linked list does not exist");
} else if ([Link] == null) { // Only one element
head = null;
} else {
Node temp = head;
while ([Link] != null) {
temp = [Link];
[Link] = null;
// Method to print the linked list
public void printList() {
Node temp = head;
while (temp != null) {
[Link]([Link] + " -> ");
temp = [Link];
[Link]("null");
// Main method to demonstrate the singly linked list operations
public static void main(String[] args) {
SinglyLinkedList list = new SinglyLinkedList();
[Link]("Insertion at start:");
[Link](50);
[Link](40);
[Link](30);
[Link](20);
[Link](10);
[Link]();
[Link]("Insertion at end:");
[Link](60);
[Link](70);
[Link](80);
[Link](90);
[Link](100);
[Link]();
[Link]("Deletion at start:");
[Link]();
[Link]();
[Link]("Deletion at end:");
[Link]();
[Link]();