You are on page 1of 3

IMPLEMENTATION OF DEQUEUE To perform the linked list implementation of Deque using C program Algorithm: 1. Start the program 2.

Declare all the required functions and select the operation to be performed 3. Allocate the memory location using malloc function and if the queue is empty then thefront and the rear element are the same 4.For deletion operation check if the queue has only one element if so perform deletion. if the queue contains more elements then perform deletion accordingly. 5.For the display operation use the while loop and check if x->link!=NULL if so print theelements. 6.For the display operation if rear== null then print that the queue is empty 7.Stop the program Program: struct node { int data; struct node *link; }; struct node *front=NULL,*rear=NULL,*x; void main()

void enqfro() { if(front==NULL) { x=(struct node*)malloc(sizeof(struct node)); printf("\nenter the data"); scanf("%d",&x->data); x->link=NULL;rear=x;front=x; } Else { x=(struct node*)malloc(sizeof(struct node)); printf("\nenter the data"); scanf("%d",&x->data); x->link=NULL; front->link=x; front=x; } } void deqrea() { if(rear==NULL) printf("\nQueue is empty");

else { x=rear; printf("\ndeleted elementis %d",x->data); rear=x->link;free(x); } } void enqrea() { if(rear==NULL) { x=(struct node*)malloc(sizeof(struct node)); printf("\nenter the data"); scanf("%d",&x->data); x->link=NULL; rear=x;front=x; } Else { x=(struct node*)malloc(sizeof(struct node)); printf("\nenter the data"); scanf("%d",&x->data); x->link=NULL; rear->link=x; rear=x; } } void deqfro() { if(front==NULL) printf("\nQueue is empty"); else { x=front; printf("\ndeleted elementis %d",x->data); front=x->link; free(x); } } void display2() { if(front==NULL) printf("\nqueue is empty"); else { x=front;

printf("\nqueue elements are"); while(x->link!=NULL) { printf("%d\t",x->data); x=x->link; } printf("%d",x->data); } } void display1() { if(rear==NULL) printf("\nqueue is empty"); else { x=rear; printf("\nqueue elements are"); while(x->link!=NULL) { printf("%d\t",x->data); x=x->link; } printf("%d",x->data); } } Output:

You might also like