0% found this document useful (0 votes)
15 views2 pages

LIST

This document is a C program that implements a simple list Abstract Data Type (ADT) with functionalities such as creating, inserting, deleting, searching, and displaying elements. The program provides a menu-driven interface for users to interact with the list. It includes error handling for invalid operations like inserting or deleting at out-of-bounds positions.

Uploaded by

sriyogeshwari22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

LIST

This document is a C program that implements a simple list Abstract Data Type (ADT) with functionalities such as creating, inserting, deleting, searching, and displaying elements. The program provides a menu-driven interface for users to interact with the list. It includes error handling for invalid operations like inserting or deleting at out-of-bounds positions.

Uploaded by

sriyogeshwari22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

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]);
}

You might also like