Professional Documents
Culture Documents
Computer Science & Engineering: Department of
Computer Science & Engineering: Department of
Experiment -1.3
Student Name: Gulshan Kumar Singh UID: 21BCS2858
Branch: CSE Section/Group: 608-B
Semester: 3rd Date of Performance: 10/09/2022
Subject Name: Data Structure Subject Code: 21CSH211
Algorithm:
1. Start.
2. Declare global and local variables for the menu-driven
program.
3. Use of for loop and if-else statements for working of
operation like Insert, Delete, Locate and Display.
4. Use while loop for iteration and declare Switch-case
statements to execute the block of codes.
5. Stop
Program code:
#include <iostream>
using namespace std;
struct Node
{
int info;
Node *link;
}*start;
void insert();
void display();
void search();
void delete_element();
int main()
{
int ch,
flag=0;
start=NULL;
while(flag!=1)
{ cout<<"\nENTER YOUR CHOICE \n";
cout<<"1)INSERT A NEW ELEMENT\n";
cout<<"2)DELETE AN ELEMENT\n";
cout<<"3)SEARCH AN ELEMENT\n";
cout<<"4)DISPLAY ELEMENT\n";
cout<<"5)Exit:\n";
cin>>ch;
DEPARTMENT OF
switch (ch)
{
case 1:
insert();
break;
case 2:
delete_element();
break;
case 3:
search();
break;
case 4:
display();
break;
case 5:
flag=1;
break;
default:
cout<<"invalid choice"<<endl;
break;
}
}
}
void insert()
{
DEPARTMENT OF
cout<<ptr->info<<endl;
if(ptr->link==NULL)
{
break;
}
ptr=ptr->link;
}
}
void delete_element()
{
struct Node *prev=NULL;
struct Node *end=start;
while(end->link)
{
prev=end;
end=end->link;
}
prev->link=NULL;
delete end;
cout<<"ELEMENT DELETED"<<endl;
}
void search()
{
int elem,fg=0;
struct Node *current=start;
DEPARTMENT OF
Output:
DEPARTMENT OF