Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TASK 4. Stacks The stack.c program below almost works, but I must have been up too late and made a bunch of silly errors. Copy

image text in transcribed
image text in transcribed
TASK 4. Stacks The stack.c program below almost works, but I must have been up too late and made a bunch of silly errors. Copy and paste the stack.c program into stack.c on your computer and fix the errors. After pasting the stack.c program onto your Ubuntu system, you can format your program by running "gg" to jump to the top and then type " =G" to indent the stack.c program. Pay attention to the basics on how the stack works. Programming languages like to push items onto the stack, then pop a few items, modify the popped data, and then push the result back onto the stack. johnho: /LAB2S cat stack.c Hinclude sstdio.h> Hindude sstring.hs Hdefine MAX_STACK_SIZE 8 Hdefine MAX_LENGTH 50 char data char stack[MAX_STACK_SIZE][MAX_LENGTH]; int top =1; int isempty0 f ift (top=1) return 1; else return 0; 1 int isfull() 1 if(top = MAX_STACK_SIZE) return 1; else return 0 ; ) 3 else printff"Pop |"\%s)" off of stack. Top of stack contains: \%sn", data, stack(topll: return data; \} else 1 printf['Error: Could not pop data. Stack is empty.ln"]: 1 1 Y else I printf("Error: Could not push V"\%s)" onto stack. 5tack is full. In", data): 1 f int main() 1 . push("Islands"); push("Channel"): printf("There are \%d items on stack. Top of stack is: \%s lnln ", top+1, peek(b): push("San"): push("Diego"): printf("There are \%6d items on stack. Top of stack is: \%s ", top+1, peek(D): pop(): pop(): printf("There are Kd items on stack. Top of stack is: \%is \an",, top+1, peek0); push("to CSU"); push("Welcome"); printff"There are \%s items on stack. Top of stack is: Sdinln", top+1, peek(D): printff"All done adding. (n); printf('Value at the top of the stack is: %s, peek[D); printtf"Pop everything off stack. (n) : printff" (n); while(lisempty()) \{ p(); 1 return 0; b 4

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

Students also viewed these Databases questions