Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Write a linked-list implementation of a queue module that has the following operations: in c 1. I... Write a linked-list implementation of a queue

Question: Write a linked-list implementation of a queue module that has the following operations: in c 1. I...

Write a linked-list implementation of a queue module that has the following operations: in c

1. Inserting an item at the end of the queue

2. Removing the first item from the beginning of the queue

3. Returning the value of the first item in the queue (without changing the queue)

4. Returning the value of the last item in the queue (without changing the queue)

5. Prints all items in the queue from beginning to end

6. Testing whether the queue is empty.

7. Deletes all nodes from the queue

8. a reverse operation

Here is exactly what you need to do Your queue should be implemented as a linked list, where each node has the value of the node and a pointer to the next node. Create a typedef for a type called Queue that defines a struct that contains two pointers that keep track of the nodes in the linked list. One pointer points to the first node in the list and one pointer points to the last node. Write an interface for the queue module in the form of a header file named queue.h that declares functions for the above operations. You are designing your own Abstract Data Type (ADT) so make sure you choose good names for your operations. Use a typedef to make the type of elements stored in your queue flexible. Your typedef can use an int in this implementation.

Write a file queue.c that contains the definitions for the functions declared in queue.h .

Write a client called queue_client.c that uses your queue module. It has only a main function (i.e., no type definitions, function prototypes, or global variables here) that allows the user to enter the operations they want to do as follows: 1 for operation 1, 2 for operation 2 etc.

Entering 1 asks the user to enter the value of the item that will be added and calls the function Part 2 implementing operation 1 above.

Entering 2 does not print any message to the user, but calls the function implementing operation 2 above.

Entering 3 prints the value returned after calling the function implementing operation 3 above.

Entering 4 prints the value returned by the function implementing operation 4 above.

Entering 5 calls the function implementing operation 5, which prints all items in the queue, each item on a line.

Entering 6 calls the function implementing operation 6 above and prints Queue is empty if the returned value is true and Queue is not empty if the returned value is false.

Entering 7 calls the function implementing operation 7 above, which delets all nodes from the queue.

The program keeps prompting the user for operations until they enter 0. The program prints Bye! when the user enters 0 and then exits.

The following is an example of the expected behavior of the program:

Enter operation: 1

Enter item to enter: 4

Enter operation: 1

Enter item to enter: 10

Enter operation: 5 4 10

Enter operation: 1

Enter item to enter: 20

Enter operation: 2

Enter operation: 5 10 20

Enter operation: 3 10

Enter operation: 4 20

Enter operation: 5 10 20

Enter operation: 6 Queue is not empty

Enter operation: 7

Enter operation: 0 Bye!

another example:

Enter operation: 1

Enter item to enter: 4

Enter operation: 1

Enter item to enter: 10

Enter operation: 1

Enter item to enter: 20

Enter operation: 1

Enter item to enter: 60

Enter operation: 1

Enter item to enter: 3

Enter operation: 5 4 10 20 60 3

Enter operation: 8

Enter operation: 5 3 60 20 10 4

Enter operation: 0 Bye!

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

More Books

Students also viewed these Databases questions

Question

Develop successful mentoring programs. page 418

Answered: 1 week ago