Answered step by step
Verified Expert Solution
Question
1 Approved Answer
*Code in C,thanks. This is a skeleton of the code and code is needed where it says /*place your code*/* #include #include #include typedef struct{
*Code in C,thanks. This is a skeleton of the code and code is needed where it says /*place your code*/* #includeImplement a stack to store and remove strings that wil be read from a file. The data file contains a series of strings, one per line. Each string will contain 255 or fewer characters Whenever you read the string "pop", this is a signal to pop your stack. Any other string should be pushed onto your stack The format of the data file is#include #include typedef struct{ char** data; /* Array of strings representing the stack */ int top; /* Index of the top of the stack. top is -1 if the stack is empty. */ int size; /* Number of elements that the stack can currently hold */ } Stack; typedef enum { FALSE, TRUE } bool; /* function prototypes */ Stack create(); void deleteStack( Stack* ps ); void push( Stack* ps, char* str ); char* pop( Stack* ps ); bool empty( Stack s ); bool full( Stack s ); int main(int argc, char *argv[]) { FILE *in_file = fopen("data_a2.txt", "r"); Stack s; printf("CS 2123 Assignment 2 "); if (in_file == NULL) { printf("File %s not found. ", "data_a2.txt"); return -1; } /* Place your code here */ /* Uncomment next line one you get create working */ //deleteStack( &s ); fclose(in_file); } /* create: returns a new empty stack. */ Stack create(){ Stack s; /* Place your code here */ return s; } /* deleteStack: deletes the memory associated with the given stack. */ void deleteStack( Stack* ps ){ while( ps->top>=0 ){ free( ps->data[ps->top] ); ps->top--; } free( ps->data ); } /* * push: takes a string parameter which is the value it pushes onto the stack. * It may also need to call realloc to expand the size of the stack before completing the push. */ void push( Stack* s, char* str ){ /* Place your code here */ } /* pop: returns the string that was removed from the stack. */ char* pop( Stack* s ){ /* Place your code here */ return NULL; } /* empty: returns TRUE if the stack has no elements, otherwise FALSE. */ bool empty( Stack s ){ /* Place your code here */ return FALSE; } /* full returns TRUE if the stack does not have any room left, otherwise FALSE. */ bool full( Stack s ){ /* Place your code here */ return FALSE; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started