Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topics: Arrays, pointers and Memory Allocation in C. For this assignment, you will write a multi-file C program to create and use a dynamic (array

image text in transcribed

Topics: Arrays, pointers and Memory Allocation in C.

For this assignment, you will write a multi-file C program to create and use a dynamic (array based) queue of float values.

A queue is a container that can be defined in terms of an array where all adds are preformed at the end of the sequence of existing values, and all removes are preformed at the start of the sequence of existing values. An empty queue is one that has no existing values in the array at all. We use the notion of a tail of the queue to keep track of (at which index) a new value in the sequence is to be added. Hence, an empty queue is one in which tail = 0 and a full queue is one in which tail = capacity

The difference with a dynamic queue is that adds never fail. After an add (que), if the queue is full, you create a new array with twice the capacity of the current array, copy all the existing items to the new array, free the memory of the old array, and set the queue pointer to the new array. Similarly, after a remove (deque) from (a non-empty queue), if the queue is less than half full, you follow the above procedure with the exception that the new array created has half the capacity of the current array.

Requirements:

  • You must write queue.h and queue.c which declares and defines functions to:
  • Create an empty queue with an initial capacity of one.
  • Add (que) an item to the queue
  • Test to see if the queue is full at capacity
  • Grow the capacity of the queue to twice its current capacity
  • Test to see if the queue is empty
  • Remove / return (deque) an item from the queue
  • Test to see if the queue is less than half full
  • Shrink the capacity of the queue in half its current capacity

  • You must write main.c which tests your queue implementation completely
  • You must write an appropriate Makefile

Notes:

  • A queue is really three separate data items: a pointer to the array, a tail indicator, and a capacity.
Topics: Arrays, pointers and Memory Allocation in C. For this assignment, you will write a multi-file C program to create and use a dynamic (array based) queue of loat values. A queue is a container that can be defined in terms of an array where all adds are preformed at the end of the sequence of existing values, and all removes are preformed at the start of the sequence of existing values. An empty queue is one that has no existing values in the array at all. We use the notion of a tail of the queue to keep track of at which index) a new value in the sequence is to be added. Hence, an empty queue is one in which tail = 0 and a full queue is one in which tail = capacity The difference with a dynamic queue is that adds "never" fail. After an add (ME), if the queue is full, you create a new array with twice the capacity of the current array, copy all the existing items to the new array, free the memory of the "old" array, and set the queue pointer to the "new" atay. Similarly, after a remove (degre) from a non-empty queue), if the queue is less than half full, you follow the above procedure with the exception that the new array created has half the capacity of the current array. Requirements: . You must write queue.h and queue.c which declares and defines functions to Create an empty queue with an initial capacity of one. Add (que) an item to the queue Test to see if the queue is full - at capacity Grow the capacity of the queue to twice its current capacity Test to see if the queue is empty Remove/retum (deque) an item from the queue Test to see if the queue is less than half full Shrink the capacity of the queue in half its current capacity You must write main.c which tests your queue implementation completely You must write an appropriate Makefile Notes: A queue is really three separate data items: a pointer to the array, a tail indicator, and a capacity. The current size (number of items in the queue) can be deduced from the tail indicator

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

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

Who is the audience?

Answered: 1 week ago

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago