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

Method for keeping two stacks within a single linear array, Q. Define a met...

Q. Define a method for keeping two stacks within a single linear array S in such a way that neither stack overflows until entire array is used and a whole stack is never shifted to

space, What is Space complexity of an algorithm? Explain

What is Space complexity of an algorithm? Explain.

Data mining, hello, i need help in data mining assignment using sas em and...

hello, i need help in data mining assignment using sas em and crisp-dm

Binary search tree, A binary search tree (BST), which may sometimes also be...

A binary search tree (BST), which may sometimes also be named a sorted or ordered binary tree, is an edge based binary tree data structure which has the following functionalities:

Order of linear search, a. In worst case the order of linear search is O (n...

a. In worst case the order of linear search is O (n/2) b. Linear search is more competent than Binary search. c. For Binary search, the array must be sorted in ascending orde

Explain best - fit method, Best - Fit Method: - This method obtains the sma...

Best - Fit Method: - This method obtains the smallest free block whose  size is greater than or equal to get such a block by traversing the whole free list follows.

Insertion in list, In the array implementation of lists, elements are store...

In the array implementation of lists, elements are stored into continuous locations. In order to add an element into the list at the end, we can insert it without any problem. But,

Sequential search of a list is preferred over binary search, What are the c...

What are the conditions under which sequential search of a list is preferred over binary search? Sequential Search is a preferred over binary search when the list is unordered

Explain circular queues, Circular Queues:- A more efficient queue repre...

Circular Queues:- A more efficient queue representation is get by regarding the array Q(1:n) as circular. It becomes more convenient to declare the array as Q(O: n-1), when  re

Searhing and sorting algorithms, how I can easily implement the bubble,sele...

how I can easily implement the bubble,selection,linear,binary searth algorithms?

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