Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab #4 Stacks Problem: Complete Exercises 5, 6, and 7 on pages 176 and 177.. Exercise 5: Describe SPECIFICALLY a. What value is displayed when

Lab #4 Stacks

Problem: Complete Exercises 5, 6, and 7 on pages 176 and 177..

Exercise 5: Describe SPECIFICALLY a. What value is displayed when the code executes? b. what mathematical function odes it evaluate?

Exercise 6: What value is displayed when the code executes?

Exercise 7: Convert the expressions from infix format to postfix format. Requirements:

You will submit the lab in written format ONLY, no coding is required.:

image text in transcribedimage text in transcribed

5. Consider the following algorithm to sort the entries in a stack S1. First create two empty stacks, S2 and S3. At any given time, stack S2 wl hold the entries in sorted order, with the smallest at the top of the stack. Move the top entry of S to S2. Pop and consider the top entry of Si. Pop entries of stack S2 and push them onto stack S3 until you reach the correct place to put . Then push t onto S2. Next move all the entries from S3 to S2. a. Write an iterative implementation of this algorithm. b. Consider the following revision of this algorithm. After moving the top entry of S to S2, compare the new top entry t of S, with the top entry of S2 and the top entry of S3. Then either move entries from S2 to S3 or from S3 to S2 until you locate the correct position for . Push t onto S2. Continue until Si is empty. Finally, move any entries remaining in S to S2. Implement this revised algorithm. 6. In the language Lisp, each of the four basic arithmetic operators appears before an arbitrary number of operands, which are separated by spaces. The resulting expression is enclosed in parentheses. The operators behave as follows: a b c.. returns the sum of all the operands, and (+) returns 0 C-ab.returs a-b-c- and a) returns-a. The minus operator must have at least one operand. a b .) returns the product of all the operands, and returns 1 (/ a b c ) returns a / b / c / , and C/ a) returns 1 / a. The divide operator must have at least one operand. You can form larger arithmetic expressions by combining these basic expressions using a fully parenthesized + -6) (2 3 4) C/C+3) C) C-2 3 1))) prefix notation. For example, the following is a valid Lisp expression: This expression is evaluated successively as follows: + -6) (2 3 4) (/ 3 1-2)) +-6 24 -1.5) 16.5 Design and implement an algorithm that uses a stack to evaluate a legal Lisp expression composed of the four basic operators and integer values. Write a program that reads such expressions and demonstrates your algorithm

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago