Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

delete and insert anode at end in doubly link list.

Posted By: GAURAV GANGWAR     Category: C Programming     Views: 12860

hi this the doubly link list program.......to insert and delete at end....

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void insert_last(int val);
int del_last();
void show();
void insert();

struct dll
{
struct dll *prev;
int info;
struct dll *next;
}*s,*e,*temp,*i;

void main()
{
int choice,val;
char ch;
insert();
do{     printf("\t\t***********************MENU*****************\n");
 printf("\t\t1-For insert node at end of doubly link list:\n");
 printf("\t\t2-For delete last node in doubly link list:\n");
 printf("\nEnter choice:");
 scanf("%d",&choice);
 switch(choice)
 {
  case 1:
  {
  printf("\nEnter a no you want to insert:");
  scanf("%d",&val);
  insert_last(val);
  show();
  break;
  }
  case 2:
  {
  val=del_last();
  printf("\ndeleted element :%d\n",val);
  printf("now updated list:\n");
  show();
  break;
  }
  }
printf("you want to continue Y/N..? ");
flushall();
scanf("%c",&ch);
}while(ch=='y'||ch=='Y');
getch();
}
 void insert()
 {     clrscr();
  printf("Enter node for link list\n");
  temp=(struct dll*)malloc(sizeof (struct dll));
  temp->next=temp->prev=NULL;
  scanf("%d",&temp->info);
  s=temp;
  e=temp;
 }


 void insert_last(int val)
 {
  temp=(struct dll*)malloc(sizeof (struct dll));
  temp->next=NULL;
  temp->info=val;
  e->next=temp;
  temp->prev=e;
  e=temp;
 }

 int del_last()
 {
  int val;
  val=e->info;
  temp=e;
  e=e->prev;
  e->next=NULL;
  free(temp);
  return(val);
 }

 void show()
 {

  for(i=s;i!=NULL;i=i->next)
  printf("%d\n",i->info);
 }

  
Share: 


Didn't find what you were looking for? Find more on delete and insert anode at end in doubly link list. Or get search suggestion and latest updates.

GAURAV GANGWAR
GAURAV GANGWAR author of delete and insert anode at end in doubly link list. is from Delhi, India. GAURAV GANGWAR says

hello friends happy to help you!!!!!!!!!!!!!!!

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!