Professional Documents
Culture Documents
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++)
{
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;
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++)
{
if (element == arr[i])
{
Index = i;
}
cout<<Index;
}
}
Output:
Screenshots
Evaluation Grid:
1. Student Performance 12
(Conduct of experiment)
2. Viva Voce 10
3. Submission(record) 8
Total 30