Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include typedef struct{ char** data; /* Array of strings representing the stack */ int top; /* Index of the top of the stack.

image text in transcribed

#include  #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; } In C and must use this skeleton code and have to fill in the code where asked to, thanks. 

*data_a2.txt is included below:

to sure Be pop pop pop you stop won't that feeling a have I but on go to much Not right Brilliant happens drink pop something and both them Ring Story ovaltine your pop pop Christmas A -- pop pop pop pop 
Implement 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 pop pop To create the initial stack, use malloc to allocate enough space to store 10 strings. Keep track of how many elements are in your stack. When you stack reaches capacity, your push method needs to allocate more space to your stack before pushing the next element (add space for another 10 strings). You can use realloc, or something else like malloc/copy/swap You do not ever need to shrink your stacks capacity You are required to implement the following stack functions: push, pop, empty, and full create returns a new empty stack 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 puslh pop returns the string that was removed from the stack empty returns TRUE if the stack has no elements, otherwise FALSE full returns TRUE if the stack does not have any room left, otherwise FALSE. Your program must print the assignment 2 and your name. Additionally, each time you read "pop" (i.e., each time you receive a signal to pop the stack) you should print the # of elements in the stack after popping and also print the string that is popped off the stack You should also print a message every time your stack grows. For example, the program might print the following Assignment 2 Problem 1 by # elements after popping: 2 # elements after popping: 1 # elements after popping: 0 Stack capacity has grown from 10 elements to 20 elements string popped: Be string popped: sure string popped: to

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

What is the principle of thermodynamics? Explain with examples

Answered: 1 week ago

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago

Question

Select suitable tools to analyze service problems.

Answered: 1 week ago