Page 120 - DCAP407_DATA_STRUCTURE
P. 120
Unit 6: Linked List Operations
}
q=START;
while(q->link->link != NULL)
{
if(q->link->value == data) //to delete element in between
{
temp=q->link;
q->link=temp->link;
free(temp);
return;
}
q=q->link;
}
if(q->link->value==data) //to delete last element
{
temp=q->link;
free(temp);
q->link=NULL;
return;
}
printf ("\n\nElement %d not found",data);
getch();
}
void Display()
{
struct node *q;
if(START == NULL)
{
printf ("\n\nList is empty");
return;
}
q=START;
printf("\n\nList is : ");
while(q!=NULL)
{
printf ("%d ", q->value);
q=q->link;
}
printf ("\n");
getch();
}
void main()
{
int choice,n,m,position,i;
START=NULL;
while(1)
{
clrscr();
printf ("1.Create List\n");
printf ("2.Delete element\n");
printf ("3.Display\n");
printf ("4.Exit\n");
printf ("\nEnter your choice:");
scanf ("%d",&choice);
switch (choice)
LOVELY PROFESSIONAL UNIVERSITY 113