ID 2023200010118 Insert
ID 2023200010118 Insert
Assignment : 04-01-2025
Posted on
Assignment : 10-01-2025
Submission Date
Submitted By
Student Code : 2 0 2 3 2 0 0 0 1 0 1 1 8
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
Node(int val) : data(val), next(nullptr) {}
};
int count = 0;
Node* temp = head;
while (temp) {
count++;
temp = temp->next;
}
temp = head;
for (int i = 1; i < mid; i++) {
temp = temp->next;
}
int main() {
Node* head = nullptr;
append(head, 1);
append(head, 2);
append(head, 3);
append(head, 4);
append(head, 5);
insertInMiddleByPosition(head, 99);
cout << "After inserting 99 (By Position): ";
printList(head);
insertInMiddleTwoPointers(head, 42);
cout << "After inserting 42 (Using Two Pointers): ";
printList(head);
return 0;
}