Professional Documents
Culture Documents
#include<conio.h>
#include<stdio.h>
struct node
{
struct node *next;
int info;
};
struct node *head;
trav=trav->next;
temp=malloc(sizeof(struct dnode));
temp->info=i;
temp->next=NULL;
trav->next=temp;
}
}
void insert_aft(int i,int pos) //FUNCTION TO INSERT AFTER A POSITION IN A LINKED LIST
{
struct node *temp,*trav;
trav=head;
for(int j=0;j<pos;j++)
{ if(trav==NULL)
{
printf(“\n POSITION DOESN’T EXIST.”);
return;
}
trav=trav->next;
}
temp=malloc(sizeof(struct dnode));
temp->info=i;
temp->next=trav->next;
trav->next=temp;
}
{
struct node *trav,ptr;
trav=head;
if(trav==NULL)
printf(“\n LIST IS EMPTY.”);
else
{
while(trav->next->next!=NULL)
{
trav=trav->next;
}
ptr=trav->next;
trav->next=NULL;
printf(“\n ELEMENT DELETED IS-:”,ptr->info);
free(ptr);
}
}
void main()
{
head=NULL;
int q,a,b,c,d;
start:
clrscr();
printf(“\n TO ADD AT THE END OF LIST PRESS 1.”);
printf(“\n TO ADD AT THE BEGINNING PRESS 2.”);
printf(“\n TO ADD IN BETWEEN PRESS 3.”);
printf(“\n TO DELETE AT THE BEGINNING PRESS 4.”);
printf(“\n TO DELETE AT THE END PRESS 5 .”);
printf(“\n TO DELETE AT A POSITION PRESS 6.”);
printf(“\n TO DISPLAY PRESS 7.”);
printf(“\n ENTER YOUR CHOICE.-:”);
scanf(“%d,&q);
switch(q)
{
case 1:
case 7:
display();
break;
default:
printf(“\n WRONG CHOICE ENTERED.”);
};
printf(“\n WISH TO CONTINUE(1/0).”);
scanf(“%d”,&d);
if(d==1)
goto start;
getch();
}
OUTPUT
TO ADD AT THE END OF LIST PRESS 1.
TO ADD AT THE BEGINNING PRESS 2.
TO ADD IN BETWEEN PRESS 3.
TO DELETE AT THE BEGINNING PRESS 4.
TO DELETE AT THE END PRESS 5 .
TO DELETE AT A POSITION PRESS 6.
TO DISPLAY PRESS 7.
ENTER YOUR CHOICE.-:1
ENTER THE NUMBER-:23
WISH TO CONTINUE(1/0).1
…
ENTER YOUR CHOICE.-:5
ELEMENT DELETED IS-:23
WISH TO CONTINUE(1/0).1
…
ENTER YOUR CHOICE.-:3
ENTER THE NUMBER-:32
ENTER THE POSITION-:1
WISH TO CONTINUE(1/0).1
…
ENTER YOUR CHOICE.-:6
ENTER THE POSITION-:1
ELEMENT DELETED IS-:32
WISH TO CONTINUE(1/0)….