Topic 2
Singly Linked List
Use class Node โ no struct allowed in exam
How It Works
A linear data structure where each Node contains data and a pointer to next node. Traversal is one-direction only (head โ NULL).
Two classes needed:
โข class Node โ holds data and next pointer
โข class LinkedList โ holds head pointer and all operations
Singly Linked List
๐
Traversal:
while(temp != NULL) โ singly specific.๐
Insert beginning: O(1). Insert end: O(n) โ must traverse.
๐
Delete end: Need second-to-last โ
temp->next->next != NULL๐
Delete by position: Traverse to pos-1, then
temp->next = temp->next->nextcomplete-singly-linked-list