DATA STRUCTURE
Programming and Technical
Programming
Technical
Write the programs for Linked List (Insertion and
Deletion) operations
Read Solution (Total 1)
-
- #include
struct node
{
int data;
struct node *next;
}*first=NULL;
// Insert operation
void insert()
{
struct node *temp;
struct node *nn=(struct node*)malloc(sizeof(struct node));
printf("enter the datan");
scanf("%d",&nn->data);
if(first!=NULL){
temp=first;
while(temp->next!=first)
temp=temp->next;
temp->next=nn;
}else{
first=nn;
}
nn->next=NULL;
}
void display()
{
struct node *temp;
temp=first;
if(temp==NULL)
{
printf("no elementsn");
return;
}
printf("elements in linked list aren");
while(temp!=NULL)
{
printf("%dn",temp->data);
temp=temp->next;
}
}
// Delete operation
void deletion()
{
struct node *temp;
temp=first;
first=first->next;
temp->next=NULL;
free(temp);
}
int main()
{
int op;
do
{
printf("1.insertionn2.deletionn3.displayn4.exitn");
printf("enter optionn");
scanf("%d",&op);
switch(op)
{
case 1:insert();
break;
case 2:deletion();
break;
case 3:display();
break;
}
}while(op!=6);
} - 6 years agoHelpfull: Yes(1) No(0)
DATA STRUCTURE Other Question