GithubHelp home page GithubHelp logo

stacks-queues's Introduction

Stacks & Queues

In this exercise we will implement both a stack & a queue, and then use them in a variety of hands-on exercises.

Due: Monday March 2nd

Learning Goals

By the end of this exercise you should be able to:

  • Implement a stack & a queue using linked lists and arrays
  • Write a Queue with a circular buffer
  • Use a stack and a queue to solve common interview problems.

Wave 1 - Implement a Stack

Using a Linked list (from a previous exercise) implement a Stack with the following methods:

  • push(value) - Adds the value to the top of the stack
  • pop - Removes and returns an element from the top of the stack
  • empty? returns true if the stack is empty and false otherwise

Wave 2 Implement a Queue

Using a circular buffer implement a Queue with the following methods:

  • enqueue(value) - Adds the value to the back of the queue.
  • dequeue - removes and returns a value from the front of the queue
  • empty? returns true if the queue is empty and false otherwise

Wave 3

Complete the methods in lib/problems.rb including:

balanced(string)

Given a string containing opening and closing braces, check if it represents a balanced expression or not.

For example:

{[{}{}]}, and {{}{}} are balanced expressions.

{()}[), and {(}) are not balanced

Optional Wave 4

evaluate_postfix(expression)

For solving a mathematical expression we sometimes use postfix form. For example: 35+ in postfix evaluates to 3 + 5 = 8.

Similarly 35+6* = (3 + 5) * 6

Here also we have to use the stack data structure to solve the postfix expressions.

From the postfix expression, when some operands are found, push them in the stack. When some operator is found, two items are popped from the stack and the operation is performed in correct sequence. After that, the result is also pushed in the stack for future use. After completing the whole expression, the final result is also stored in the stack top.

Example: Input and Output

Input: Postfix expression: 53+62/*35*+

Output: The result is: 39

Additional Exercise

If you finish the previous waves, complete breadth-first-search on the binary trees project using a Queue.

stacks-queues's People

Contributors

cheezitman avatar dtaylor73 avatar kaidamasaki avatar mmcknett avatar sudocrystal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.