LIST ADT USING LINKED LIST
#include <iostream> using namespace std; struct Node { int data; Node* next; }; Node* head = nullptr; void insert() { int value; cout << "\nEnter the element to insert: "; cin >> value; Node* newNode = new Node{value, nullptr}; if (!head) { head = newNode; } else { newNode->next = head; head = newNode; } } void display() { if (!head) { cout << "\nList is empty\n"; return; } Node* temp = head; cout << "\nList elements:\n"; while (temp) { cout << temp->data << " "; temp = temp->next; } cout << "\n"; } int main() { ...
Comments
Post a Comment