Question: Implement the following functions of a stack that stores C strings as its items(read the .h file for full details on how each function should

Implement the following functions of a stack that stores C strings as its items(read the .h file for full details on how each function should behave): cStringStack* cStringStack_create();

void cStringStack_push(cStringStack* csStack, char* cStr);

char* cStringStack_pop(cStringStack* csStack);

bool cStringStack_isEmpty(cStringStack* csStack);

void cStringStack_free(cStringStack* csStack);

void cStringStack_reverse(cStringStack* csStack);

cStringStack* cStringStack_duplicate(cStringStack* csStack);

Note that since the number of C strings to be stored is unknown, your implementation should dynamically grow/shrink by requesting/releasing memory to add/remove items. It must not use any size in advance. The provided test3.c file implements a simple program that reads in user inputs and stores them into the stack structure. It will only be fully working if you have correctly implemented all the functions above. See the sample outputs as examples:

#ifndef A3_Q3_H #define A3_Q3_H

#include #include #include #include

typedef struct { int size; char** items; } cStringStack;

//creates a new stack following the struct defined //a new stack has size = 0 and items = NULL cStringStack* cStringStack_create();

//pushes a given C string to the stack, //you must copy the content instead of just the address void cStringStack_push(cStringStack* csStack, char* cStr);

//pops the C string from the stack, //implemented by returning the address of the C string (copy) //if the stack has 1 item, once popped it should become the same as a new stack, //if the stack is empty, return NULL char* cStringStack_pop(cStringStack* csStack);

//checks if the stack is empty bool cStringStack_isEmpty(cStringStack* csStack);

//frees all the memory used by the stack to store the C strings void cStringStack_free(cStringStack* csStack);

//reverse the order of the C strings stored so the first added one // will be popped first, and so on void cStringStack_reverse(cStringStack* csStack);

//creates a copy of a stack, //each item has to be a C string with the same content but in different address cStringStack* cStringStack_duplicate(cStringStack* csStack);

#endif

Implement the following functions of a stack that stores C strings as

Input a command and press enter, use "undo" to remove previous, or quit" to quit: undo Stack is empty, nothing to pop. undo as the first command Input a command and press enter, use 'undo" to remove previous, or "quit" to quit: ls Input a command and press enter, use "undo" to remove previous, or "quit" to quit: quit Input a command and press enter, use "undo" to remove previous, or "quit" to quit: mkdir Assignment2 ls mkdir Assignment3 cd Assignment3 Input a command and press enter, ls use "undo" to remove previous, mkdir Assignment3 or "quit" to quit: undo cd Assignment3 Previous being removed: mkdir Assignment2 Input a command and press enter, cd Assignment3 use "undo" to remove previous, mkdir Assignment3 or "quit" to quit: is mkdir Assignment3 Input a command and press enter, ls use "undo" to remove previous, mkdir Assignment3 or "quit" to quit: cd Assignment3 cd Assignment3 Left: a sequence of inputs. Right: ended with the command "quit. Only include the function definitions in your answer and name the source file containing them as question3.c

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!