Question: Write C programs queue.h, queue.c to implement the queue data structure by a linked list. queue.h contains the following type definition and function prototypes. queue.c

Write C programs queue.h, queue.c to implement the queue data structure by a linked list. queue.h contains the following type definition and function prototypes. queue.c contains the implementation of the functions.

  1. definition of queue node structure type QNODE which contains int data and queue node next pointer.
  2. void enqueue(QNODE **frontp, QNODE **rearp, int value); this creates a node and sets its data to value and inserts it to the rear end of the queue passed by frontp and rearp.
  3. int dequeue(QNODE **frontp, QUEUE **rearp); this gets the data of front node, deletes the front node and returns the data.
  4. int peek(QNODE *front); this returns the data of front node.
  5. Write the main function program a6q2.c to test the above functions.

queue.h

#ifndef QUEUE_H #define QUEUE_H #include  #include  typedef struct node { int data; struct node *next; } QNODE; void enqueue(QNODE **frontp, QNODE **rearp, int); int dequeue(QNODE **frontp, QNODE **rearp); int peek(QNODE *front); void clean(QNODE **frontp, QNODE **rearp); #endif

queue.c

#include "queue.h" void enqueue(QNODE **frontp, QNODE **rearp, int val) { // your code } int dequeue(QNODE **frontp, QNODE **rearp) { // your code } int peek(QNODE *front) { // your code } void clean(QNODE **frontp, QNODE **rearp) { // your code }

this can be tested by the following code below

#include #include

#include "queue.h"

int main(int argc, char* args[]) { QNODE *front = NULL, *rear = NULL; int i=0; for (i=1; i<=12; i++) { enqueue(&front, &rear, i); } printf("%d ", peek(front)); dequeue(&front, &rear); printf("%d ", dequeue(&front, &rear)); printf(" "); while (front != NULL) { printf("%d ", dequeue(&front, &rear)); } for (i=1; i<=12; i++) { enqueue(&front, &rear, i); } clean(&front, &rear);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!