answersLogoWhite

0


Best Answer

#include <stdio.h>

#include <conio.h>

#include <alloc.h>

struct node

{

int data ;

struct node *link ;

} ;

struct dqueue

{

struct node *front ;

struct node *rear ;

} ;

void initdqueue ( struct dqueue * ) ;

void addqatend ( struct dqueue *, int item ) ;

void addqatbeg ( struct dqueue *, int item ) ;

int delqatbeg ( struct dqueue * ) ;

int delqatend ( struct dqueue * ) ;

void display ( struct dqueue ) ;

int count ( struct dqueue ) ;

void deldqueue ( struct dqueue * ) ;

void main( )

{

struct dqueue dq ;

int i, n ;

clrscr( ) ;

initdqueue ( &dq ) ;

addqatend ( &dq, 11 ) ;

addqatbeg ( &dq, 10 ) ;

addqatend ( &dq, 12 ) ;

addqatbeg ( &dq, 9 ) ;

addqatend ( &dq, 13 ) ;

addqatbeg ( &dq, 8 ) ;

addqatend ( &dq, 14 ) ;

addqatbeg ( &dq, 7 ) ;

display ( dq ) ;

n = count ( dq ) ;

printf ( "\nTotal elements: %d", n ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatend ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

display ( dq ) ;

n = count ( dq ) ;

printf ( "\nElements Left: %d", n ) ;

deldqueue ( &dq ) ;

getch( ) ;

}

/* initializes elements of structure */

void initdqueue ( struct dqueue *p )

{

p -> front = p -> rear = NULL ;

}

/* adds item at the end of dqueue */

void addqatend ( struct dqueue *p, int item )

{

struct node *temp ;

temp = ( struct node * ) malloc ( sizeof ( struct node ) );

temp -> data = item ;

temp -> link = NULL ;

if ( p -> front NULL )

return ;

while ( p -> front != NULL )

{

temp = p -> front ;

p -> front = p -> front -> link ;

free ( temp ) ;

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

First, while a linked list is certainly a good container for a queue, it isn't a queue. It is a list. A list can have items randomly added and removed at any given location. A queue is a container where you push items into the queue by enqueuing an remove items by dequeuing. It may be better to think of a queue as a FIFO.

That said, a double linked list is linked forward and in reverse. So each element has a reference to the next item in the list and a link to the previous item as well.

When you enqueue items, you would for example insert an item at the start of the list. This item would have no previous element, but will point to the old first element as its next element.

When you dequeue from the list, you will "pop" the element that is referenced as the last element of the list. Then you'll set the next last item to be the item referenced by the item you popped as the old last item. You would then removed the reference tonthe next item from the new tail element.

Hope this helps!

- Darren

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Illustrate to implement deque using circular linked list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Explain The merits of using a deque to implement a stack in data structure?

Explain The merits of using a deque to implement a stack in data structure


Write a algorithm for a deque operations?

please read data structure (schaum series) books


What is the need of deque?

A double ended queue (or deque ) is a queue where insertion and deletion can be performed at both end that is front pointer can be used for insertion (apart from its usual operation i.e. deletion) and rear pointer can be used for deletion (apart from its usual operation i.e. insertion). So when we need to insert or delete at both end we need deque.


What is queue explain the basic element of queue?

The queue is a linear data structure where operations of insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Following are the types of queue: Linear queue Circular queue Priority queue Double ended queue ( or deque )


C program for the two dimensional array repesentation of priority queue?

//implement double ended queue using array. #include&lt;stdio.h&gt; #include&lt;conio.h&gt; #define SIZE 20 typedef struct dq_t { int front,rear; int item[SIZE]; }deque; /********** Function Declaration begins **********/ void create(deque *); void display(deque *); void insert_rear(deque *, int); void insert_front(deque *, int); int delete_front(deque *, int); int delete_rear(deque *, int); /********** Function Declaration ends **********/ void main() { int data,ch,x; deque DQ; clrscr(); create(&amp;DQ); printf("\n\t\t Program shows working of double ended queue"); do { printf("\n\t\t Menu"); printf("\n\t\t 1: insert at rear end"); printf("\n\t\t 2: insert at front end"); printf("\n\t\t 3: delete from front end"); printf("\n\t\t 4: delete from rear end"); printf("\n\t\t 5: exit. "); printf("\n\t\t Enter choice :"); scanf("%d",&amp;ch); switch(ch) { case 1: if (DQ.rear &gt;= SIZE) { printf("\n Deque is full at rear end"); continue; } else { printf("\n Enter element to be added at rear end :"); scanf("%d",&amp;data); insert_rear(&amp;DQ,data); printf("\n Elements in a deque are :"); display(&amp;DQ); continue; } case 2: if (DQ.front &lt;=0) { printf("\n Deque is full at front end"); continue; } else { printf("\n Enter element to be added at front end :"); scanf("%d",&amp;data); insert_front(&amp;DQ,data); printf("\n Elements in a deque are :"); display(&amp;DQ); continue; } case 3: x = delete_front(&amp;DQ,data); if (DQ.front==0) { continue; } else { printf("\n Elements in a deque are :"); display(&amp;DQ); continue; } case 4: x = delete_rear(&amp;DQ,data); if (DQ.rear==0) { continue; } else { printf("\n Elements in a deque are :"); display(&amp;DQ); continue; } case 5: printf("\n finish"); return; } } while(ch!=5); getch(); } /********** Creating an empty double ended queue **********/ /********** Function Definition begins **********/ void create(deque *DQ) { DQ-&gt;front=0; DQ-&gt;rear =0; } /********** Function Definition ends **********/ /********** Inserting element at rear end **********/ /********** Function Definition begins **********/ void insert_rear(deque *DQ, int data) { if ((DQ-&gt;front 0) { printf("\n Underflow"); return(0); } else { DQ-&gt;rear = DQ-&gt;rear -1; data = DQ-&gt;item[DQ-&gt;rear]; printf("\n Element %d is deleted from rear:",data); } if (DQ-&gt;front==DQ-&gt;rear) { DQ-&gt;front =0; DQ-&gt;rear = 0; printf("\n Deque is empty(rear end)"); } return data; } /********** Function Definition ends **********/ /********** Displaying elements of DEQUE **********/ /********** Function Definition begins **********/ void display(deque *DQ) { int x; for(x=DQ-&gt;front;x&lt;DQ-&gt;rear;x++) { printf("%d\t",DQ-&gt;item[x]); } printf("\n\n"); } /********** Function Definition ends **********/

Related questions

C program to implement deque using circular linked list?

You'll need to use a doubly-linked circular list, since otherwise when you pop off the tail element you'll need to whizz all the way round the list to find its predecessor. See the links section for an implementation of a doubly-linked circular list.


Explain The merits of using a deque to implement a stack in data structure?

Explain The merits of using a deque to implement a stack in data structure


What are types of Queue?

Queue is a data structure which is based on FIFO that is first in first out. Following are the types of queue: Linear queue Circular queue Priority queue Double ended queue ( or deque )


What is difference between enque and dequeue?

deque


How do you write a program to delete elements at both ends of a deque using C plus plus?

The C++ STL (Standard Template Library) provides a std::deque template specifically for this purpose: std::deque&lt;int&gt; deq {}; // default construct an empty deque of type int deq.push_back (42); // deq = {42} deq.push_front (0); // deq = {0, 42} deq.push_back (100); // deq = {0, 42, 100} deq.pop_front (); // deq = {42, 100} deq.pop_back (); // deq = {42} As with all other STL containers, any type or class that can be copy or move constructed can be placed in a std::deque, including other STL containers (even std::deque itself).


Program to delete elements at both ends in a dequeue using c plus plus?

#include&lt;deque&gt; std::deque&lt;int&gt; deq; deq.push_back (42); deq.pop_back (); deq.push_front (0); deq.pop_front ();


What is the birth name of Danny Demanto?

Danny Demanto's birth name is Daniel C. DeQue.


Write a algorithm for a deque operations?

please read data structure (schaum series) books


What do you understand by deque?

A double ended queue (or deque ) is a queue where insertion and deletion can be performed at both end that is front pointer can be used for insertion (apart from its usual operation i.e. deletion) and rear pointer can be used for deletion (apart from its usual operation i.e. insertion)


What is the need of deque?

A double ended queue (or deque ) is a queue where insertion and deletion can be performed at both end that is front pointer can be used for insertion (apart from its usual operation i.e. deletion) and rear pointer can be used for deletion (apart from its usual operation i.e. insertion). So when we need to insert or delete at both end we need deque.


Which data structure allows deletion from both ends and insertion only from one end?

Deque double ended queue


What has the author Nicolaus written?

Nicolaus has written: 'Tractatus sacerdotalis de sacramentis deque divinis officiis et eorum administratibus'