Question
3. A Queue is designed to be deterministic with a fixed maximum length. The struct of Queue is below: a currEvent and an array. {currEvent,
3.
A Queue is designed to be deterministic with a fixed maximum length.
The struct of Queue is below: a currEvent and an array.
{currEvent, {[0: Ex], [1: Ex], [2: Ex], [3: Ex]}}
An example of Queue is below.
{E3, {[0: END], [1: E2], [2: END], [3: E1]}}
It means the current pending event is E3. The following events in order are E1 and E2.
The currEvent E3 points to [3: E1], where 3 is the index of the array and E1 means the next event E1.
Then, the next event E1 points to [1: E2], where 1 is the index of the array and E2 means the next event E2.
Then, the next event E2 points to [2: END], where 2 is the index of the array and END means the end, i.e. no more events.
When the Queue has no events, it has the following:
{END, {[0: END], [1: END], [2: END], [3: END]}}
(a) Assume in the system, the events happened in the following time order:
T0: no events in queue.
T1: E1 is added to the queue.
T2: E0 is added to the queue.
T3: E3 is added to the queue.
T4: E1 is popped from the queue.
T5: E2 is added to the queue.
Follow the style below, show the queues after the time points, T1, T2, T3, T4, T5.
Time | currEvent | [0: x] | [1: x] | [2: x] | [3: x] |
T0 | END | [0: END] | [1: END] | [2: END] | [3: END] |
T1 |
| [0: ] | [1: ] | [2: ] | [3: ] |
T2 |
| [0: ] | [1: ] | [2: ] | [3: ] |
T3 |
| [0: ] | [1: ] | [2: ] | [3: ] |
T4 |
| [0: ] | [1: ] | [2: ] | [3: ] |
T5 |
| [0: ] | [1: ] | [2: ] | [3: ] |
(b) Write four functions:
1. void initializeQueue(Queue* que)
2. bool isEmpty(Queue* que)
3. uint8_t pop(Queue* que)
4. void append(Queue* que, unit8_t ev)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started