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, 1. Show the effect of each of the following operations on queue q. A...

1. Show the effect of each of the following operations on queue q. Assume that y (type Character) contains the character ‘&’. What are the final values of x and success (type boole

Grounded header link list and a circular header link list, What is the diff...

What is the difference between a grounded header link list and a circular header link list? A header linked list is a linked list which always having a special node, known as t

Deletion from a red-black tree, Deletion in a RBT uses two main processes, ...

Deletion in a RBT uses two main processes, namely, Procedure 1: This is utilized to delete an element in a given Red-Black Tree. It involves the method of deletion utilized in

Stack and array, how to implement multiple stack using single dimension arr...

how to implement multiple stack using single dimension array in c

Recursive function , Q. Write down the recursive function to count the numb...

Q. Write down the recursive function to count the number of the nodes in the binary tree.    A n s . R ecursive Function to count no. of Nodes in Binary Tree is writt

Graphs with negative edge costs, We have discussed that the above Dijkstra'...

We have discussed that the above Dijkstra's single source shortest-path algorithm works for graphs along with non-negative edges (like road networks). Given two scenarios can emerg

Design the system for seller, Your program should include three components ...

Your program should include three components selling, buying and managing for the use of sellers, buyers and the Manager, respectively. Provide a menu for a user to enter each comp

Applications of binary trees, In computer programming, Trees are utilized ...

In computer programming, Trees are utilized enormously. These can be utilized for developing database search times (binary search trees, AVL trees, 2-3 trees, red-black trees), Gam

Abstract Data Types, A useful tool which is used for specifying the logical...

A useful tool which is used for specifying the logical properties of a data type is called the abstract data type or ADT. The term "abstract data type" refers to the fundamental ma

Applications of linear and binary search, The searching method are applicab...

The searching method are applicable to a number of places in current's world, may it be Internet, search engines, text pattern matching, on line enquiry, finding a record from data

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