Professional Documents
Culture Documents
Linked List Programs
Linked List Programs
t
Name
Muhammad Hamza
Roll No
F22NSEEN1M01006
Submitted to
Dr. Hina Afreen
#include <iostream>
// Node structure
struct Node {
int data;
Node* next;
};
private:
Node* head;
};
int main() {
LinkedList linkedList;
return 0;
}
#include <iostream>
// Node structure
struct Node {
int data;
Node* next;
};
if (current != nullptr) {
newNode->next = current->next;
current->next = newNode;
} else {
cout << "Invalid position. Node not inserted." << endl;
}
}
}
private:
Node* head;
};
int main() {
LinkedList linkedList;
return 0;
}
#include <iostream>
// Node structure
struct Node {
int data;
Node* next;
};
if (head == nullptr) {
// If the list is empty, make the new node the head
head = newNode;
} else {
// Traverse the list to find the last node and append the new node
Node* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = newNode;
}
}
private:
Node* head;
};
int main() {
LinkedList linkedList;
return 0;
}
#include <iostream>
// Node structure
struct Node {
int data;
Node* next;
};
private:
Node* head;
};
int main() {
LinkedList linkedList;
return 0;
}
#include <iostream>
// Node structure
struct Node {
int data;
Node* next;
};
delete current;
} else {
cout << "Invalid position. Node not deleted." << endl;
}
}
private:
Node* head;
};
int main() {
LinkedList linkedList;
return 0;
}
#include <iostream>
// Node structure
struct Node {
int data;
Node* next;
};
if (head->next == nullptr) {
// If there is only one node in the list
delete head;
head = nullptr;
return;
}
private:
Node* head;
};
int main() {
LinkedList linkedList;
// Get user input for the number of nodes to delete from the end
int numNodesToDelete;
cout << "Enter the number of nodes to delete from the end: ";
cin >> numNodesToDelete;
return 0;
}