1. Stacks (10 points)
Draw a sequence of diagrams, one for each problem segment, that represent the current state of the
stack after each labeled set of operations. If an operation or instruction produces output then indicate
what that output is. hStack is the handle of a stack opaque object that can hold characters. There is
no diagram for init or destroy.
hStack = stack_init_default();
i. stack_push(hStack, ’a’);
i. stack_push(hStack, ’b’);
iii. printf("%c ", stack_top(hStack)); stack_pop(hStack);
iv. printf("%c ", stack_top(hStack)); stack_push(hStack, ’c’);
v. stack_push(hStack, ’d’); stack_push(hStack, ’e’);
vi. printf("%c ", stack_top(hStack)); stack_push(hStack, ’f’);
vii. stack_pop(hStack); stack_push(hStack, ’g’);
stack_destroy(&hStack);
This study source was downloaded by 100000899606070 from CourseHero.com on 02-20-2026 22:53:14 GMT -06:00
https://www.coursehero.com/file/192612150/COMP1020-Exam11pdf/
, COMP.1020 Computing II UMASS - Lowell Exam 1 Spring 2023 2
2. Queues (10 points)
Draw a sequence of diagrams, one for each problem segment, that represent the current state of the
queue after each labeled set of operations. If an operation or instruction produces output then indicate
what that output is. We will use the function enqueue to add to the queue and serve to remove from the
queue. hQueue is the handle of a queue opaque object that can hold characters. There is no diagram
for init or destroy. hQueue = queue_init_default();
i. queue_enqueue(hQueue, ’a’);
ii. queue_enqueue(hQueue, ’b’);
iii. printf("%c, " queue_front(hQueue)); queue_enqueue(hQueue, ’c’);
iv. printf("%c ", queue_front(hQueue)); queue_enqueue(hQueue, ’d’);
v. queue_serve(hQueue); queue_serve(hQueue);
vi. printf("%c ", queue_front(hQueue)); queue_enqueue(hQueue, ’e’);
vii. queue_serve(hQueue); queue_serve(hQueue);
hQueue->destroy(&hQueue);
This study source was downloaded by 100000899606070 from CourseHero.com on 02-20-2026 22:53:14 GMT -06:00
https://www.coursehero.com/file/192612150/COMP1020-Exam11pdf/