Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

show work please

Answered: 1 week ago

Question

My opinions/suggestions are valued.

Answered: 1 week ago