Project: Stacks and Queues

This is mostly an academic exercise, so you will be asked to refrain from using queue-like or stack-like methods in your solution, however tempting this otherwise sensible choice would be.

Introduction

This exercise will be a small one to give you an appreciation of how queues and stacks work. Of course, a great way to figure out how anything works is to make the thing yourself, so this is what we will be doing in this lesson. This is mostly an academic exercise, so you will be asked to refrain from using queue-like or stack-like methods in your solution, however tempting this otherwise sensible choice would be.

Assignment

In your language of choice...

  1. Create a "Stack" class, which will have a private array member variable, and two public methods '#push(item)' and '#pop'. Push should add item to the end of your array, and pop should remove from the end.

    • If you're using Ruby, Javascript or similar languages, please try and do this without using the array's push and pop methods for this exercise!

  2. Create a "Queue" class, which will have a private array member variable, and two public methods '#enqueue(item)' and '#dequeue'. Enqueue should add item to one end of the array, and Dequeue should remove from the other end.

    • Like with "Stack", please refrain from using 'push' and 'shift' if you're using a language that has these (or similar) methods!

Last updated