Submit to Blackboard before the deadline. You will be able to revise your answers until the deadline with no penalty.
IMPORTANT: By submitting your answers, you are certifying that these answers have been exclusively your own work. All students enrolled in this course are expected to adhere to the UT Arlington Honor Code:
I pledge, on my honor, to uphold UT Arlington's tradition of academic integrity, a tradition that values hard work and honest effort in the pursuit of academic excellence. I promise that I will submit only work that I personally create or contribute to group collaborations, and I will appropriately reference any work from other sources. I will follow the highest standards of integrity and uphold the spirit of the Honor Code.
int stack_length(Stack stack)
that
counts and returns the number of items in a stack, and satisfies the following requirements:
As an example, consider the following main function:
int main() { Stack stack = newStack(); pushInt(stack, 10); pushInt(stack, 20); pushInt(stack, 30); printf("before counting the length, the stack is:\n"); printIntStack(stack); int length = stack_length(stack); printf("the length of the stack is %d\n", length); printf("after counting the length, the stack is:\n"); printIntStack(stack); destroyStack(stack);}If you correctly implement the
stack_length
function, this main function should print:
before counting the length, the stack is: position 0 from the top: 30 position 1 from the top: 20 position 2 from the top: 10 the length of the stack is 3 after counting the length, the stack is: position 0 from the top: 30 position 1 from the top: 20 position 2 from the top: 10Of course, it is not sufficient for your function to only behave correctly in the above example, it should work with any example, and stacks of any size.
void reverse_stack(Stack stack)
that reverses the order of items in its argument stack, under the following requirements:
#include "stacks.h"
As an example, consider the following main function:
int main() { Stack stack = newStack(); pushInt(stack, 10); pushInt(stack, 20); pushInt(stack, 30); printf("before reversing, the stack is:\n"); printIntStack(stack); reverse_stack(stack); printf("after reversing, the stack is:\n"); printIntStack(stack); destroyStack(stack); }If you correctly implement the
reverse_stack
function, this main function should print:
before reversing, the stack is: position 0 from the top: 30 position 1 from the top: 20 position 2 from the top: 10 after reversing, the stack is: position 0 from the top: 10 position 1 from the top: 20 position 2 from the top: 30Of course, it is not sufficient for your function to only behave correctly in the above example, it should work with any example, and stacks of any size.
Your put
and get
functions should produce errors and exit the program when the queue is respectively full or empty, in exactly the same way in which push
and pop
behave in stacks_arrays.c.
As an example, consider the following main function:
int main() { Queue queue = newQueue1(4); int value; putInt(queue, 15); putInt(queue, 20); value = getInt(queue); printf("got value %d\n", value); putInt(queue, 30); putInt(queue, 7); putInt(queue, 25); value = getInt(queue); printf("got value %d\n", value); putInt(queue, 12); value = getInt(queue); printf("got value %d\n", value); value = getInt(queue); printf("got value %d\n", value); destroyQueue(queue); }If you correctly implement the FIFO queue interface, this main function should print:
got value 15 got value 20 got value 30 got value 7Of course, it is not sufficient for your function to only behave correctly in the above example, it should work with any example, and queues of any size.
Your get
function should produce an error and exit the program when the queue is empty, in exactly the same way in which pop
behave in stacks_lists.c.
The example main function from task three should produce the exact same output for task 4.
The assignment should be submitted via Blackboard. Submit a ZIPPED directory called assignment.zip. No other forms of compression are accepted, contact the instructor or TA if you do not know how to produce .zip files. The zipped directory should contain the following documents:
IMPORTANT: Pay close attention to all specifications on this page, including file names and submission format. Even in cases where your answers are correct, points will be taken off liberally for non-compliance with the instructions given on this page (such as wrong file names, wrong compression format for the submitted code, and so on). The reason is that non-compliance with the instructions makes the grading process significantly (and unnecessarily) more time consuming. Contact the instructor or TA if you have any questions.
Back to the list of assignments.