Wonderful Queue
First, learn the facts about queues and stacks:
Queues (and stacks) are said to be "abstract data types" insofar as they can each be implemented with different data structures. For instance, a queue, q
, for Jack’s shirts, initially empty, could be implemented using an array in C as follows, wherein CAPACITY
is a constant and shirt
is a type, both defined elsewhere:
typedef struct
{
int size;
shirt shirts[CAPACITY];
}
queue;
queue q;
q.size = 0;
Alternatively, Jack’s queue could be implemented using a linked list in C as follows, wherein shirt
is again a type defined elsewhere:
typedef struct node
{
shirt s;
struct node *next;
}
node;
node *q = NULL;
Even more simply could Jack’s queue be implemented using a list
in Python as follows:
q = list()
Answer the below in queue.md
, explaining each advantage you cite in no more than 2 sentences.
Questions
-
(2 points.) What’s one advantage of implementing, in C, a queue using an array instead of a linked list?
-
(2 points.) What’s one advantage of implementing, in C, a queue using a linked list instead of an array?
-
(2 points.) What’s one advantage of implementing a queue using Python instead of C?
-
(2 points.) What’s one advantage of implementing a queue using C instead of Python?
-
(2 points.) Via what single line of code could you enqueue (i.e., add) a shirt,
s
, toq
in Python? Via what single line of code could you then dequeue (i.e., remove) another shirt fromq
in Python?
Debrief
-
Which resources, if any, did you find helpful in answering this problem’s questions?
-
About how long, in minutes, did you spend on this problem’s questions?