Linked list implementation of any circular queue, Data Structure & Algorithms

Assignment Help:

Link list representation of a circular queue is more efficient as it employs space more competently, of course with the added cost of storing the pointers. Program 7 gives the linked list representation of any circular queue.

Program: Linked list implementation of any Circular queue

#include "stdio.h"

struct cq

{     int value;

int *next;

};

typedef struct cq *cqptr cqptr p, *front, *rear;

main()

{

int choice,x;            /* Initialise the circular queue */

cqptr = front = rear = NULL;

printf ("for insertion  enter # and for  deletion  enter $ from the queue")

printf("Enter your choice")

scanf("%d",&choice);

switch (choice)

{

case 1 :

printf ("Enter element for insertion in linked list :");

scanf("%d",&x);

add(&q,x);

break;

case 2 :

delete();

break;

}

}

//* Insertion of element *//

add(int value)

{

struct cq *new;

new = (struct cq*)malloc(sizeof(queue));

new->value = value new->next = NULL;

if (front == NULL)

{

cqptr = new;

front = rear = queueptr;

}

else

{

rear->next = new;

rear=new;

}

}

/*deletion of element */

delete()

{

int delvalue = 0;

if (front == NULL)

{

printf("Queue get empty");

delvalue = front->value;

if (front->next==NULL)

{

free(front);

queueptr = front = rear = NULL;

}

else

{

front=front->next;

 free(queueptr);

queueptr = front;

}

}

}


Related Discussions:- Linked list implementation of any circular queue

Queue, what''s queue ?

what''s queue ?

Balance theorem, Question 1 Discuss the following theorems with respect to...

Question 1 Discuss the following theorems with respect to Splay Trees- Balance Theorem Dynamic Finger Theorem   Question 2 Write a C program for implementation

Arrays, Data array A has data series from 1,000,000 to 1 with step size 1, ...

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

Differentiate between nonpersistent and 1-persistent, Differentiate between...

Differentiate between Nonpersistent and 1-persistent Nonpersistent: If the medium is idle, transmit; if the medium is busy, wait an amount of time drawn from a probability dist

Efficiency of binary search, Each of the comparison in the binary search de...

Each of the comparison in the binary search decrease the number of possible candidates where the key value can be searched by a factor of 2 as the array is divided into two halves

Characteristics of good algorithms, What do we mean by algorithm? What are ...

What do we mean by algorithm? What are the characteristics of a good and relevant algorithm? An algorithm is "a step-by-step procedure for finishing some task'' An algorithm c

Define the terms - key attribute and value set, Define the terms   ...

Define the terms     i) Key attribute     ii) Value set  Key attribute:  An entity  type  usually  has  an attribute  whose  values  are  distinct  fr

A binary tree in which levels except possibly the last, A binary tree in wh...

A binary tree in which if all its levels except possibly the last, have the maximum number of nodes and all the nodes at the last level appear as far left as possible, is called as

Advanced trees, Linked list representations contain great advantages of fle...

Linked list representations contain great advantages of flexibility on the contiguous representation of data structures. However, they contain few disadvantages also. Data structur

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd