






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Note: For task # 01 & 02: The given below Menu base program contain operation on stack using linked list
#include
cout<<"\n\n\tElement deleted Sucessfully....!!!"<<endl; } } void showstack() { Node *q; q=top; if(top==NULL){ cout<<"\n\n\t\tStack is empty!!"; } else{ cout<<"\n\n\t\tList of Stack element "; while(q!=NULL) { cout<<q->data<<" "; q=q->next; } } } int main() { int ch,x; Node *nptr; while(1) { cout<<"\n\t >>>>>>>> Menu of Stack using Linked list <<<<<<<<"; cout<<"\n"; cout<<"\n\t-------------------------------------------------------------"; cout<<"\n\tENTER 1: Push / Insert element"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 2: Pop / Delete element"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 3: Displaying linked list"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 4: To Exit"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\n\tPlease Enter Your Choice: "; cin>>ch; switch(ch){ case 1: system("cls"); cout<<"\n\t\tENTER AN ELEMENT TO BE INSERTED :"; cin>>x; nptr=newnode(x); push(nptr);Sleep(2000);system("cls"); break; case 2: system("cls"); pop();Sleep(2000);system("cls"); break; case 3: system("cls"); showstack();Sleep(3000);system("cls"); break; case 4: exit(0); default: cout<<"\nWrong choice!!"; }
Option#2 is used to delete element in stack using linked list as shown in figs
using namespace std; struct node { int data; struct node next; }; struct node front = NULL; struct node* rear = NULL; struct node* temp;
void Insert() { int val; cout<<"\n\t\tENTER AN ELEMENT TO BE INSERTED :"; cin>>val; if (rear == NULL) { rear = (struct node *)malloc(sizeof(struct node)); rear->next = NULL; rear->data = val; front = rear; } else { temp=(struct node *)malloc(sizeof(struct node)); rear->next = temp; temp->data = val; temp->next = NULL; rear = temp; } cout<<"\n\t\tElement inserted Sucessfully....!!!"<<endl; }
void Delete() { temp = front; if (front == NULL) { cout<<"\n\n\t\tQueue is Underflow"<<endl; return; } else if (temp->next != NULL) { temp = temp->next; cout<<"\n\n\tElement deleted from queue is : "<<front->data<<endl; free(front); front = temp; } else { cout<<"\n\n\tElement deleted from queue is : "<<front->data<<endl; free(front); front = NULL; rear = NULL; } cout<<"\n\n\tElement deleted Sucessfully....!!!"<<endl; }
Note: For task # 03 & 04: The given below Menu base program contain operation on Queue using linked list
#include
cin>>ch; switch (ch) { case 1: system("cls");Insert();Sleep(2000);system("cls"); break; case 2: system("cls");Delete();Sleep(2000);system("cls"); break; case 3: system("cls");Display();Sleep(3000);system("cls"); break; case 4: cout<<"Exit"<<endl; break; default: cout<<"Invalid choice"<<endl; } } while(ch!=4); return 0; }
Option#1 is used to EnQueue using linked list as shown in figs
Option#3 is used to Display list of Queue using linked list as shown in fig Option#2 is used to DeQueue using linked list as shown in figs