How to write a c program to Create, Display, Insert and deletion of queue elements/Queue Implementation using doubly linked list in C Programming Language ?
Soution:
/* Create, Display, Insert and deletion of queue elements */
#include <stdio.h>
#include <stdlib.h>
struct queue* head, * tail;
void create(int);
void display ();
void insert (int);
void delete();
struct queue
{
int data;
struct queue *rptr,*lptr;
};
int main()
{
int i,n,b,value;
head=tail=NULL;
printf("\nEnter the option\n");
do
{
printf("\nEnter:\n1->Creation of Queue\n2->Display the queue\n3->Insert a member in the queue\n4->Delete a member of the queue\n0->Exit\n");
scanf("%d",&b);
switch(b)
{
case 1: printf("\nHow many nodes you want to enter\n");
scanf("%d", &n);
for(i=0; i< n; i++)
{
printf("\nEnter the value to be inserted in the queue\n");
scanf("%d",&value);
create(value);
}
break;
case 2: display();
break;
case 3: printf("\nEnter the value to be inserted in the queue\n");
scanf("%d",&value);
insert(value);
break;
case 4: delete();
break;
case 0: break;
}
if(b==0)
exit(0);
}
while(b!=0);
}
void create(int value)
{
struct queue* nn= malloc (sizeof (struct queue));
struct queue* temp= head;
nn->data=value;
nn->lptr=NULL;
nn->rptr=NULL;
if(head == NULL)
head=tail=nn;
else
{
while(temp->rptr != NULL)
temp = temp->rptr;
temp->rptr=nn;
nn->lptr= temp;
tail=nn;
}
}
void display()
{
int b;
struct queue* temp;
printf("\nPress:\n1->To print in forward direction\n2->To print in reverse direction\n");
scanf("%d", &b);
switch(b)
{
case 1: temp=head;
while(temp != NULL)
{
printf("\n%d\n",temp->data);
temp = temp->rptr;
}
break;
case 2: temp=tail;
while(temp != NULL)
{
printf("%d\n",temp->data);
temp=temp->lptr;
}
}
}
void insert(int value)
{
struct queue* nn=(struct queue*)malloc(sizeof(struct queue));
printf("\nInserting %d into the queue from rear end\n", value);
nn->data=value;
nn->rptr=NULL;
tail->rptr=nn;
nn->lptr=tail;
tail=nn;
}
void delete()
{
struct queue* temp;
temp=head;
head=head->rptr;
printf("\nDeleting %d from the queue from front end\n", temp->data);
free (temp);
head->lptr= NULL;
}
Learn More :
Implementation
- C Program To Implement Heap Sort
- Implements an 8-bit sample and hold ADC on the MSP430
- C Program to Implements a dictionary's functionality.
- C Program to Implements a dictionary's functionality
- C Program to Implementation of List ADT as linked-list
- Pre Order, Post order, In order Implement Binary Tree using linked list
- Implementation of your "Fury of Dracula" Dracula AI
- C Program to Implement Dijkstra's Algorithm
- C Program to Implement Quick Sort
- C Program to Implemention Bubble Sort using array
- Linked List For Getting Employee Details, Display and Search For Salary C Program
Doubly Linked List
Create
- How To Write a C program that creates customers' bills for a carpet company when the following is given ?
- C Program to Create VIRUS
- Creates new main.c with empty main boilerplate template
- C Program to create a solution to the Towers of Hanoi game
- C Program to Create a copy of an image
- Ardunio: Create a crystal ball to tell you the future C Program
- C Program to Creating pico device
- Add x and y coordinates to create a new struct in C Program
- C program allocates new nodes and creates a four element list with fixed values
- C Program To Create Two Singly Linked List and Perform Following Operation
- Create Two Singly Linked List Perform Differences Display It C Program
- C Program Implement Binary Search Tree And Its Traversals
- Creation and Display of Elements in Both Forward and Reverse Direction in a Doubly Linked List
- Calculator Using IF-ELSE in C Program
Element
- Given a numerical value, check if at least one of the elements of the vector is equal to the numerical value if so, say where in the negative case, say that there is no.
- C program to Given a vector (integer or real), determine what is the maximum value of element what is the position in which this element is located
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program Array NxM Elements Geometric/Arithmetic
- C Program To Returns the nth element of the Fibonacci sequence.
- C Program to search an element using linear search or binary search (menu driven program)
- Fibonacci Multi Threaded C Program To Print Element Of Fibonacci Series
- C Program to accept n numbers from user & find out the maximum element out of them by using dynamic memory allocation
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C program to reverse an array elements using Dynamic Memory Allocation
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- C Program to accept n numbers from user store these numbers into an array & reverse an array elements using function
- C Program to accept 5 names from user & store these names into an array. Sort these array elements in alphabetical order
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- C Program to Implemention Bubble Sort using array
- Creation and Display of Elements in Both Forward and Reverse Direction in a Doubly Linked List
Deletion
Insertion
Display
- DISPLAY SOURCE CODE AS OUTPUT IN C PROGRAM
- Sort Three Numbers - program reads in three Integers and displays them in ascending order.
- C Program To Display The Number In A Specific Formats
- C Program that Display a IBM Logo
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- LED ON OFF For One Sec/Count and Display on the Attached Serial Monitor
- Pre Order, Post order, In order Implement Binary Tree using linked list
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C Program to accept n numbers & store all prime numbers in an array & display this result
- C program to display the transpose of given 3 X 3 matrix
- C Program to accept a string from user, delete all vowels from that string & display the result
- C Program To Create Two Singly Linked List and Perform Following Operation
- Create Two Singly Linked List Perform Differences Display It C Program
- Creation and Display of Elements in Both Forward and Reverse Direction in a Doubly Linked List
- C Program to Display a real time clock (HH:MM:SS) on the LCD
- Program to Display Pie Chart Accepting User Input C Program
- Linked List For Getting Employee Details, Display and Search For Salary C Program
- Menu driven program in the creation,display,search, insertion and deletion of a node in the linked list
- Program to display the following pattern in C
- Display the Following Pattern * ** *** **** ***** C Program