CS 240: Algorithms and Data Structures
James Madison University, Fall 2021

Stack-Based Expression Evaluation










Matching Parentheses

Write pseudocode for an algorithm that checks a string to see if it contains correctly matched pairs of brackets and parentheses. Test your algorithm on the following inputs: "[()]", "[]()", "[(])", "((", "))".

  ALGORITHM: CheckMatches
      INPUT:  I -  A string containing only the characters '[', ']', '(' and ')'.
      OUTPUT: True if the string contains only correctly matched brackets
              and parentheses, False otherwise.














Queue Using Stacks

Implement the Queue ADT using only stacks to store information. Analyze the running time of each operation.


// Declare instance variables...




StackQueue() {





}

void enqueue(E item) {








}


E dequeue() {







}


Stack Using Queues

Implement the Stack ADT using only queues to store information. Analyze the running time of each operation.


// Declare instance variables...




QueueStack() {







}

void push(E item) {







}

E pop() {









}


List Using Stacks

Implement the following subset of the List ADT using only Stacks to store information. Analyze the running time of each operation.


// Declare instance variables...





StackList() {






}

void insert(E item) {







}

E remove() {







}

void moveToPos(int pos) {








}