Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C

C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C Programming C You are going to implement stack abstract data type using linked list implementation. The header file "lab3-42.h" and the description of the functions are as follows. Your program should not contain main(). Name your program as lab3-q2.c. // lab3-92.h 1/ Cannot modify: struct node, Stack struct node { char data; struct node *next; }; typedef strugt node Stack; // Return a new empty stack #1 #9 // An empty stack is data storing CHAR_MAX and next pointing to NULL void stack_init(Stack** s); // Make the stack empty #2 void stack_make_empty(Stack* s); // Return the size of the stack #3 int stack_size(Stack* s); // Check if the stack is empty #4 !/ Return 1 if empty, return o if not empty int stack_is_empty(Stack* s); // Push the value x to the top of the stack #5 #9 void stack_push(Stack* s, char x); // Return the topmost element of the stack #6 #9 // If the stack is empty, return o char stack_top(Stack* s); // If s is not empty, pop an element from the stack #7 #9 void stack_pop(Stack* s); // Free the stack, if the stack is not NULL #8 #9 1/ Assign NULL to q after free void stack_free (Stack** s); // Print the stack in the format #9 #10 11 e.g. s: a b c d, where d is the topmost element // output: "(top) dcba" char* stack_print(Stack* s); #include "lab3-42.h" #include #include #include #include /* Return a new empty stack #1 #9 */ /* An empty stack is data storing CHAR_MAX and next pointing to NULL */ void stack_init(Stack** s){ /* Your code here */ } /* Make the stack empty #2 */ void stack_make_empty(Stack* s) { /* Your code here */ } /* Return the size of the stack #3 */ int stack_size(Stack* s) { /* Your code here */ return 0; } /* Check if the stack is empty #4 #9 */ /* Return 1 if empty, return o if not empty */ int stack_is_empty(Stack* s){ /* Your code here */ return 0; } /* Push the value x to the top of the stack #5 #9 */ void stack_push(Stack* s, char x){ /* Your code here */ } /* Return the topmost element of the stack #6 #9 */ /* If the stack is empty, return 0 */ char stack_top(Stack* s){ /* Your code here */ return 0; } /* If s is not empty, pop an element from the stack #7 #9 * / void stack_pop(Stack* s){ /* Your code here */ } /* Free the stack, if the stack is not NULL #8 #9 */ /* Assign NULL to 4 after free */ void stack_free(Stack** s) { /* Your code here */ } /* Print the stack in the format #9 #10 */ /* e.g. s: a b cd, where d is the topmost element */ /* output: "(top) dcba" */ char* stack_print(Stack* s) { char *output; /* Your code here */ return output; } #include "lab3-42.h" #include #include #include #includelimits.h> int main(int argc, char *argv[]){ FILE *fout; Stack *s; int isCorrect; fout = fopen(argv[1], "w"); /* default, your program is correct */ isCorrect = 1; /* check the function, stack_init() */ S = NULL; stack_init(&s); /* if stack_init() is not implemented appropriately */ if (s == NULL) { isCorrect = 0; } else if (s->next != NULL || s->data != CHAR_MAX) { isCorrect = 0; } 1* output "Correct" if the stack_init() is correctly implemented */ if (isCorrect == 1) { fprintf(fout, "Stack: Correct "); } else { fprintf(fout, "Stack: Wrong Answer "); } fclose(fout); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

9781285586618

Students also viewed these Programming questions

Question

List the main components of executive compensation packages.

Answered: 1 week ago