| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Module 4 - Stacks

Page history last edited by Dr. Ron Eaglin 7 years, 11 months ago

 

Information

 

Module 4 follow the materials available at Topic - Stacks and Queues. You should have a good understanding of Lists at  Topic - Basic Data structures as a Queue and a Stack are simply implementation of a List with specific properties.

 

Exercises

 

Assignment 1 -

 

Implement a Stack in Javascript (you will turn in a link to your program in JSFiddle). Do not use an array as the stack or in the implementation of the stack.

 

Build a Stack Computer from your stack.  When a number is entered it goes onto the top of the stack. When an operation is entered, the previous 2 numbers are operated on by the operation and the result is pushed onto the top of the stack. This is how an RPN calculator.

 

For example

2 [enter]   2

5 [enter]   5 2

*  [enter]  * 5 2 -> collapses to 10

 

would leave at 10 at the top of the stack.

 

The program should use a simple input box, either a text field or prompt and display the contents of the Stack.

 

Contents of Stack:

 

Quizzes (Quiz Submission Instructions )

 

Quiz 1 - Complete Quiz at http://geeksquiz.com/data-structure/stack/ 

 

Assignment Grading - Implementation of a Stack using an array will not be accepted (no grade will be assigned). A stack computer created using a Stack (with correct push and pop) that performs all operations correctly - and does not allow bad entries (non-numeric or operation, no operations until 2 numbers on stack) will be worth full credit. 

 

Additional

 

The stack computer concept can easily be made into a Tetris style game. Imagine numbers falling onto multiple Stacks - these numbers pile up unless the user applies an operator to the stack. Operators would operate on the last 2 numbers performing the operation. When the user gets 3 common numbers in a single row - they are removed and the row collapses further.

 

Question: What kind of structure and algorithm is needed to make a game like this?

 

Previous: Module 3 - Lists

Next: Module 5 - Queues

Comments (0)

You don't have permission to comment on this page.