Professional Documents
Culture Documents
void display_list() {
Student* current = head;
while (current != nullptr) {
std::cout << "Roll Number: " << current->roll_number
<< ", Name: " << current->name << "\n";
current = current->next;}
}
~StudentLinkedList() {
Student* current = head;
Student* next_node;
while (current != nullptr) {
next_node = current->next;
delete current;
current = next_node; }
}
};
int main() {
cout<<"ANSH BALGOTRA"<<endl;
StudentLinkedList linked_list;
linked_list.insert_at_position(101, "John", 1);
linked_list.insert_at_position(102, "Alice", 2);
linked_list.insert_at_position(103, "Bob", 3);
std::cout << "Initial Linked List:\n";
linked_list.display_list();
std::cout << "\nInserting a new student at position 2:\n";
linked_list.insert_at_position(104, "Charlie", 2);
linked_list.display_list();
std::cout << "\nDeleting student with Roll Number 102:\n";
linked_list.delete_node(102);
linked_list.display_list();
std::cout << "\nReversing the linked list:\n";
linked_list.reverse_list();
linked_list.display_list();
return 0;}
OUTPUT: