b20f4607ce112eff3f18d00ca76e5912844b3eed
haas/fall2026/data/projects/dlq0.md
| ... | ... | @@ -0,0 +1,84 @@ |
| 1 | +# PROJECT: DOUBLY LINKED QUEUES (dlq0) |
|
| 2 | + |
|
| 3 | +## OBJECTIVE |
|
| 4 | + |
|
| 5 | +Building on top of your doubly-linked list implementation, implement |
|
| 6 | +a queue. |
|
| 7 | + |
|
| 8 | +## TASK |
|
| 9 | + |
|
| 10 | +By the deadline, please do the following: |
|
| 11 | + |
|
| 12 | +- create a `Queue` management struct, containing a `size` element, |
|
| 13 | +a `front` `Node` pointer, a `back` `Node` pointer, and a `data` `List` |
|
| 14 | +pointer |
|
| 15 | + * `size`, if 0, will indicate an unbounded queue (positive means bounded) |
|
| 16 | + * `front` points to the node at the front of the queue (where nodes leave) |
|
| 17 | + * `back` points to the node at the back of the queue (where nodes join) |
|
| 18 | + * `data` points to the underlying list the queue is built upon |
|
| 19 | +- implement an `mkqueue()` function |
|
| 20 | +- implement an `rmqueue()` function |
|
| 21 | +- implement an `enqueue()` function |
|
| 22 | +- implement a `dequeue()` function |
|
| 23 | + |
|
| 24 | +## BACKGROUND |
|
| 25 | + |
|
| 26 | +A queue is a FIFO (First-In, First-Out) data structure, which we |
|
| 27 | +will simplify by building on top of our existing doubly-linked list |
|
| 28 | +infrastructure. |
|
| 29 | + |
|
| 30 | +The first item placed into the queue will be the first item retrieved |
|
| 31 | +from the queue. Think of a line at a store: those who arrive first are |
|
| 32 | +served first, and newcomers join at the end of the line. |
|
| 33 | + |
|
| 34 | +The strength of the queue comes from the particular restrictions we place |
|
| 35 | +on its access: we only add at one end (the **back**), and we only remove |
|
| 36 | +from the other (the **front**). Nodes in the middle of the queue are not |
|
| 37 | +directly accessible. These two ends will correspond to the start and end |
|
| 38 | +of your underlying list (your implementation, you pick which end of the |
|
| 39 | +list is the front and which is the back, but be consistent, and run with |
|
| 40 | +it). |
|
| 41 | + |
|
| 42 | +The queue `enqueue()` function will take the node and place it at the back |
|
| 43 | +of the queue (by calling the appropriate underlying list function), adjusting |
|
| 44 | +`back` (and, if the queue was empty, `front`) accordingly. |
|
| 45 | + |
|
| 46 | +The queue `dequeue()` function will retrieve the node at the front of the |
|
| 47 | +queue (by calling the appropriate underlying list function), adjusting |
|
| 48 | +`front` (and, if the queue is now empty, `back`) to reflect the new state |
|
| 49 | +of the queue. |
|
| 50 | + |
|
| 51 | +You will want to call upon the underlying list functionality to do the |
|
| 52 | +heavy-lifting. The `front` and `back` pointers exist to keep the queue's |
|
| 53 | +view of its endpoints up to date; the `data` list pointer is how you |
|
| 54 | +reach the list functions that actually manipulate the nodes. |
|
| 55 | + |
|
| 56 | +For the queue, **ENQUEUE** and **DEQUEUE** are the two central actions. |
|
| 57 | +Without them there is no queue. |
|
| 58 | + |
|
| 59 | +Be mindful of the following scenarios, as they are common sources of |
|
| 60 | +error: |
|
| 61 | + |
|
| 62 | +- enqueueing onto an empty queue (both `front` and `back` must be set) |
|
| 63 | +- dequeueing the last remaining node (both `front` and `back` must be |
|
| 64 | + cleared) |
|
| 65 | +- dequeueing from an empty queue (should fail gracefully) |
|
| 66 | +- enqueueing onto a full (bounded) queue (should fail gracefully) |
|
| 67 | + |
|
| 68 | +## SUBMISSION |
|
| 69 | + |
|
| 70 | +``` |
|
| 71 | +182:dlq0:final tally of results (182/182) |
|
| 72 | +*:dlq0:create queue struct [26/26] |
|
| 73 | +*:dlq0:create and test mkqueue function [26/26] |
|
| 74 | +*:dlq0:create and test rmqueue function [26/26] |
|
| 75 | +*:dlq0:create and test enqueue function [52/52] |
|
| 76 | +*:dlq0:create and test dequeue function [52/52] |
|
| 77 | +``` |
|
| 78 | + |
|
| 79 | +Additionally: |
|
| 80 | + |
|
| 81 | +- Solutions not abiding by spirit of project will be subject to a 25% overall deduction |
|
| 82 | +- Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction |
|
| 83 | +- Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction |
|
| 84 | +- Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction |