0% found this document useful (0 votes)
16 views1 page

PRGM 16

The document outlines a C++ program for creating a linked list with functionalities to insert and delete nodes at the end. It includes a structure definition for nodes, functions for insertion, deletion, and displaying the list, as well as a main menu for user interaction. The program handles cases for empty lists and provides feedback on operations performed.

Uploaded by

divya R K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

PRGM 16

The document outlines a C++ program for creating a linked list with functionalities to insert and delete nodes at the end. It includes a structure definition for nodes, functions for insertion, deletion, and displaying the list, as well as a main menu for user interaction. The program handles cases for empty lists and provides feedback on operations performed.

Uploaded by

divya R K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

16.

Program to create a linked list anad delete a Node* prev = NULL;


node at the end. while (temp->next != NULL)
{
#include <iostream.h> prev = temp;
#include <conio.h> temp = temp->next;
#include <stdlib.h> }
struct Node { cout << "Deleted item is: " << temp->info << "\n";
int info; prev->next = NULL;
Node* next; delete temp;
}; }
Node* head = NULL; // Display the list
// Insert at the END of the list void ldisplay()
void linsert() {
{ if (head == NULL)
Node* q = new Node(); {
int item; cout << "List is empty\n";
cout << "Enter the element to be inserted at the return;
end: "; }
cin >> item; Node* temp = head;
q->info = item; cout << "Contents of the list are:"<<endl;
q->next = NULL; while (temp != NULL)
if (head == NULL) {
{ cout << temp->info << " -> ";
head = q; temp = temp->next;
} }
else cout << "NULL\n";
{ }
Node* temp = head; // Main function
while (temp->next != NULL) int main()
{ {
temp = temp->next; int ch;
} while (1)
temp->next = q; {
} cout << "\nLINKED LIST MENU"<<endl;
} cout << "1. Insert at end"<<endl;
// Delete from the END of the list cout << "2. Delete at end" <<endl;
void ldelete() cout << "3. Display "<<endl;
{ cout << "4. Exit"<<endl;
if (head == NULL) cout << "Enter your choice: ";
{ cin >> ch;
cout << "List is empty\n"; switch (ch)
return; {
} case 1: linsert();
if (head->next == NULL) break;
{ case 2: ldelete();
cout << "Deleted item is: " << head->info << "\n"; break;
delete head; case 3: ldisplay();
head = NULL; break;
return; case 4: exit(0);
} default: cout << "Invalid choice\n";
Node* temp = head; }}}

You might also like