You are on page 1of 5

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

EXPERIMENT: 1.3
Aim: Write a menu driven program that maintains a linear linked list whose elements are
stored in on ascending order and implements the following operations (using separate
functions):
a) Insert a new element
b) Delete an existing element
c) Search an element
d) Display all the elements

Program Code:

#include<stdio.h>
#include<conio.h>
#include<iostream>
void a_insert(int,int);
void a_delete(int);
void a_location(double);
void a_traverse();
int arr[10], n;
int main()
{
int k;
std::cout<<"enter length";
std::cin>>n;
std::cout<<"array is:";
for(k=0;k<n;k++)
{

NAME: (ABHIJEET DATA UID:


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

std::cin>>arr[k];
}
int ch;
int num,pos; double element; while(ch!=5)
{
std::cout<<"1> Insert";
std::cout<<"\n2> Delete";
std::cout<<"\n3> location";
std::cout<<"\n4> Show";
std::cout<<"\n5> Quit\n";
std::cin>>ch;
switch(ch)
{
case 1:std::cout<<"enter element:";
std::cin>>num;
std::cout<<"enter pos.:";
std::cin>>pos; a_insert(num,pos); break;
case 2:std::cout<<"enter pos.:";
std::cin>>pos;
a_delete(pos); break;
case 3:std::cout<<"enter element"; a_location(element);
break;
case 4:std::cout<<"\nArray:"; a_traverse();
break;

NAME: (ABHIJEET DATA UID:


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

case 5:break;
default:std::cout << "Invalid input" << std::endl;
}
}
getch();
}
void a_insert(int num, int pos)
{
for(int i=5; i>=pos;i--) arr[i]=arr[i-1]; arr[i]=num;n++;
}
void a_delete(int pos)
{
for(int i=pos; i<=n;i++) arr[i-1]=arr[i];
arr[i-1]=0;
}
void a_traverse()
{
int i;
std::cout<<"array is:"<<endl; for(i=0;i<n;i++)cout<<arr[i]<<endl;
}
void a_location(double element)
{
cin>>element; int Index;
for (int i=0;i<5; i++)
{

NAME: (ABHIJEET DATA UID:


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

if (element == arr[i])
{
Index = i;
}
cout<<Index;
}
}

Output:
Screenshots

NAME: (ABHIJEET DATA UID:


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Learning outcomes (What I have learnt):


1. I have learnt about in this experiment introduction of Data structure using C++.
2. I learnt how apply different operations on data structure (i.e. array).
Operations like traversal, insertion, deletion, deletion and Updation.
3. I also learn about self referential structure.

Evaluation Grid:

Sr. No. Parameters Maximum Marks Marks Obtained

1. Student Performance 12
(Conduct of experiment)
2. Viva Voce 10

3. Submission(record) 8

Total 30

NAME: (ABHIJEET DATA UID:

You might also like