Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int data;
- struct node *next,*prev;
- }node;
- typedef struct
- {
- node *start,*last;
- }head;
- void insertend(head *t,int ele)
- {
- node *p;
- p = (node*)malloc(sizeof(node));
- p->data=ele;
- p->next=p->prev=NULL;
- if(t->start==NULL)
- {
- t->last=t->start=p;
- return;
- }
- t->last->next = p;
- p->prev = t->last;
- t->last = p;
- return ;
- }
- void displayrev(head *t)
- {
- node *q;
- if(t->start==NULL&&t->last==NULL)
- {
- printf("\nLinked list is empty");
- return;
- }
- printf("\nElement of Linked list is given below\n");
- for(q=t->last;q!=NULL;q=q->prev)
- {
- printf("%d\t",q->data);
- }
- return;
- }
- void deletebeg(head *t)
- {
- int z;
- node *p;
- if(t->start==NULL)
- {
- printf("Linked list is Empty");
- return;
- }
- p=t->start;
- z = p->data;
- if(t->start==t->last)
- {
- t->start=t->last=NULL;
- }
- else
- {
- t->start = t->start->next;
- t->start->prev = NULL;
- }
- printf("deleted element in Linked list %d",z);
- return;
- }
- void display(head *t)
- {
- node *q;
- if(t->start==NULL&&t->last==NULL)
- {
- printf("\nLinked list is empty");
- return;
- }
- printf("\nElement of Linked list is given below\n");
- for(q=t->start;q!=NULL;q=q->next)
- {
- printf("%d\t",q->data);
- }
- return;
- }
- int main()
- {
- head x;
- int ch,ele;
- x.start=x.last=NULL;
- printf("\nImplementation of Doubly Linked list with function insertend,display,deletebeg,reversedisplay\n");
- while(1)
- {
- printf("\nenter choice \n1.InsertEnd 2.Deletebeg 3.Reversedisplay 4.display 5.Exit\n");
- scanf_s("%d",&ch);
- if(ch==5)
- {
- break;
- }
- else
- {
- switch(ch)
- {
- case 1:printf("\nenter element to insert");
- scanf_s("%d",&ele);
- insertend(&x,ele);
- break;
- case 2:deletebeg(&x);
- break;
- case 3:displayrev(&x);
- break;
- case 4:display(&x);
- break;
- default:printf("\ninvalid input");
- }
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement