In this question we get a stack of chars. The implementation is given in a separate file. You should not make assumptions about the exact implementation details. You may only use the following functions to access the stack. typedef struct { // not known
IN C
In this question we get a stack of chars. The implementation is given in a separate file. You should not make assumptions about the exact implementation details.
You may only use the following functions to access the stack.
} stack_t;
// creates a new stack stack_t* stack_create(); // pushes a given item to the stack void stack_push(stack_t* s, char item); // removes the top element from the stack and returns it // Pre condition: stack is not empty char stack_pop(stack_t* s); // checks if the stack is empty bool stack_is_empty(stack_t* s); // frees the stack void stack_free(stack_t* s);-
a) Write a function that gets a stack of chars and returns the number of elements in it. When the function returns, the stacks must be in their initial state. // returns the size of the stack
int stack_size(stack_t* s) -
b) Write a function that gets two stacks of chars and checks if they are equal (i.e., have the same elements in the same order). When the function returns, the stacks must be in their initial state.
bool stack_equal(stack_t* s1, stack_t* s2)
// checks if the two stacks are equal -
c) Write a function that gets a stack of chars and returns the string consisting of the chars in it. When the function returns, the stack must be in its initial state.
// converts stack to a string
// For example, suppose we push 'A', then 'B', and then 'C'. The function needs to return the string "ABC".
char* stack_to_string(stack_t* s)
Step by step
Solved in 2 steps