Question: In C, Implement each of the functions to create a working stack 6 II-Implement each of the functions to create a working stack. 7 II

In C, Implement each of the functions to create a working stack

In C, Implement each of the functions to create a working stack6 II-Implement each of the functions to create a working stack. 7

6 II-Implement each of the functions to create a working stack. 7 II -Do not change any of the function declarations I-(i.e. stack t* create stack) should not have additional arguments) II-You should not have any 'printf' statements in your stack functions 10 II(You may consider using these printf statements to debug, but they should be removed from your final version) 12 #ifndefMYSTACK_A 13 #define MYSTACKH 14 15 I/ Stores the maximum "depth' of our stack. 16 I/Our implementation enforces a maximum depth of our stack. 17 II (i.e. capacity cannot exceed MAX_DEPTH for any stack) 18 # define MAXDEPTH 32 19 20 II Create a node data structure to store data within 21 1I our stack. In our case, we will stores integers 22 typedef struct nodet 23 24 25 node t; 26 27 // Create a stack data structure 28 II Our stack holds a single pointer to a node, which 9 I1 is a linked list of nodes. 30 typedef struct stackf 31 32 - int data struct node* next; int count; // count keeps track of how many items // are in the stack. unsigned int capacity; // Stores the maximum size of our stack node t* head; 34 35 stack_t; 36 37 II Creates a stack 38 //Returns a pointer to a newly created stack. 39 II The stack should be initialized with data on the heap. 0 11 (Think about what the means in terms of memory allocation) 41 / The stacks fields should also be initialized to default values. 42 stack t* create_stack (unsigned int capacity) 43 // head points to a node on the top of our stack. // Modify the body of this function as needed stack-t* myStack = NULL; 45 46 47 return myStack; 49 // Stack Empty 50 /Check if the stack is empty 51 I/ Returns 1 if true (The stack is completely empty) 52 IIReturns 0 if false (the stack has at least one element enqueued) 53 int stack_empty (stack t* s) return 0; 56 57 58 I1 Stack Full 59 II Check if the stack is full 60 I/ Returns 1 if true (The Stack is completely full, i.e. equal to capacity) 61 I/ Returns 0 if false (the Stack has more space available to enqueue items) 62 int stack_full (stack t* s) 63 64 65 return 0 67 II Enqueue a new item 68 II i.e. push a new item into our data structure 69 II Returns a -1 if the operation fails (otherwise returns on success) 70 I/ (i.e. if the Stack is full that is an error, but does not crash the program). 71 int stack_enqueue (stackt s, int item) 72 73 74 75 /IDequeue an item 76 II Returns the item at the front of the stack and 77 II removes an item from the stack. 78 I/ Removing from an empty stack should crash the program, call exit (1) 79 int stack_dequeue (stack_t *s)f 80 81 82 83 84 II Stack Size 85 I Queries the current size of a stack 86 II A stack that has not been previously created will crash the program. 87 II (i.e. A NULL stack cannot return the size) 88 unsigned int stack_size(stack t* s) 89 90 91 92 II Free stack 93 I/ Removes a stack and ALL of its elements from memory 94 IIThis should be called before the proram terminates. 95 void free_stack (stack t* s) 96 97 return -1; / Note: you should have two return statements in this function. return 9999999; // Note: This line is a 'filler' so the code compiles. return 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!