Deletes the last node and updates the next pointer.
O(n)
O(1)
Circular Traversal
Traverses the list starting from the head.
O(n)
O(1)
Check if Circular
Checks if the list is circular.
O(n)
O(1)
Insert At End
void insertAtEnd(CNode*& head, int value) { CNode* newNode = new CNode(value); if (head == nullptr) { // Empty list case head = newNode; newNode->next = head; // Point to itself return; } CNode* temp = head; while (temp->next != head) { temp = temp->next; } temp->next = newNode; newNode->next = head;}
Delete From End
void deleteFromEnd(CNode*& head) { if (head == nullptr) return; // Empty list case if (head->next == head) { // Only one node in the list delete head; head = nullptr; return; } CNode* temp = head; while (temp->next->next != head) { temp = temp->next; } delete temp->next; temp->next = head;}