LIST
LIST
h>
#include<conio.h>
#define MAX 10
void create();
void insert();
void deletion();
void search();
void display();
int ch,list[20],found=0,i,pos,n,key,ele;
void main()
{
clrscr();
do
{
printf("\n Main Menu");
printf("\n 1.Create \n 2.Insert \n 3.Delete \n 4.Search \n 5.Display\n 6.Exit \n");
printf("\n Enter your Choice:");
scanf("%d", &ch);
switch(ch)
{
case 1:
create();
break;
case 2:
insert();
break;
case 3:
deletion();
break;
case 4:
search();
break;
case 5:
display();
break;
}
}while(ch!=6);
getch();
}
void create()
{
printf("\n Enter the number of nodes :");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("\n Enter the Element:",i+1);
scanf("%d", &list[i]);
}
}
void deletion()
{
printf("\n Enter the position u want to delete::");
scanf("%d", &pos);
if(pos>=n)
printf("\n Invalid Location::");
else
{
for(i=pos+1;i<n;i++)
list[i-1]=list[i];
n--;
}
printf("\n The Elements after deletion");
for(i=0;i<n;i++)
printf("\t%d", list[i]);
}
void search()
{
printf("\n Enter the Element to be searched:");
scanf("%d",&key);
for(i=0;i<n;i++)
if(list[i]==key)
{
found=1;
break;
}
if(found==1)
printf("Value is in the %d Position",i);
else
printf("Value %d is not in the list::",key);
}
void insert()
{
printf("\n Enter the position u need to insert::");
scanf("%d", &pos);
if(pos>=n)
printf("\n invalid Location::");
else
{
for(i=MAX-1;i>=pos-1;i--)
list[i+1]=list[i];
printf("\n Enter the element to insert::\n");
scanf("%d",&ele);
list[pos]=ele;
n++;
}
printf("\n The list after insertion::\n");
display();
}
void display()
{
printf("\n The Elements of The list ADT are:");
for(i=0;i<n;i++)
printf("\t%d",list[i]);
}