Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need this in C programming language. Please help. Question 2: STACK: Part I 30 pts] (a) (12 points) You are given the following requirements

I need this in C programming language. Please help.

image text in transcribed

image text in transcribed

image text in transcribed

Question 2: STACK: Part I 30 pts] (a) (12 points) You are given the following requirements for a stack ahetract data type: (a) It must be able to set up enough memory to accommodate the stack (b) It must be possible to make a stack empty, i.e. without freeing the memory. (c) It must be possible to push a given element on to a stack. (d) It must be possible to pop the topmost element from a stack. (e) It must be possible to free all the memory used by the stack. Write a contract for a stack abstract data type. Express your contract in the form of an ap programming interface (what we called API in class) using an opaque object, with a comment specify- ing the expected behavior of each function. Note: You shall need to specify the opaque object before using it. (b) (3 points) Briefly describe a possible representation for a stack. (5 points) For the describe representation in (b above, write c structure. you gave in (e) and your API (n a), complete the definition aemory for the stack structure, i.e. an initialization function. (d) (10 points) Given the stack representation of the function that reserves enough r This function should return an opaque handle. (e) (10 points) A stack machine has instructions that push integers on to a stack and pop integers of the stack. A typical stack machine has instructions such as those summarized in Table ?? below. Instruction Effect LOAD i-- Push the integer i on to the stack. ADD Pop two integers off the stack, add them, and push the result back on to the stack. p two integers of the stack, subtract the top most integer from the integet SUB and push the result back on to the stack Pop two integers of the stack, multiply and push the result back on to the stack. MIL MULT Table 1: Summary of stack machine instructions be A stack machine makes it easy to evaluate complicated expressions. Any integer expression can translated to stack machine code. After the code is executed, t which is the result of evaluating the expression. For example: he stack will contain a single integer, Expected result +34 Expression Stack machine code 1+(56)1TOADA LOADSLOADEMULT.ADD AD Draw diagrams showing the contents of the stack after executing each instruction in the stack machine code "LOAD 4; LOAD 5; LOAD 6; MULT; ADD". Assume your stack representation of part (C)

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_2

Step: 3

blur-text-image_3

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

2 What are the advantages and disadvantages of job evaluation?

Answered: 1 week ago