Notes 2
Notes 2
Notes 2
3.2 Insertion:
• At the Beginning: Insert a new node before the head and update the head pointer.
• At the End: Traverse to the last node and update its next pointer to the new node.
• At a Specific Position: Traverse to the required position and adjust pointers accordingly.
3.3 Deletion:
• From the Beginning: Update the head pointer to the next node.
• From the End: Traverse to the second-last node and set its next pointer to NULL.
• From a Specific Position: Adjust pointers to bypass the node to be deleted.
3.4 Searching:
• Traverse the list to find a specific value or node.
3.5 Reversal:
• Reverse the direction of pointers in the list.
// Node structure
struct Node {
int data;
struct Node* next;
};
int main() {
struct Node* head = createNode(1);
head->next = createNode(2);
head->next->next = createNode(3);
printList(head);
return 0;
}
// Node structure
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
int main() {
struct Node* head = createNode(1);
struct Node* second = createNode(2);
struct Node* third = createNode(3);
head->next = second;
second->prev = head;
second->next = third;
third->prev = second;
printListForward(head);
return 0;
}