Stacks and Queues as Interfaces


Prerequisites

In this interface Magercise, a special sort of stack is given two completely different apperances though the use of interfaces.

The stack here, QStack, is both a queue and a stack, implementing both add and remove methods expected by queue users, and push and pop methods expected by stack users. QStack will be implemented using the Vector class, all pushing, popping, adding and removing activites are done in terms of Objects.

Two methods are given, doStackStuff and doQueueStuff to excercise the QStack. These methods, and the main method, may be examined to help determine how to write the needed code.

Interfaces are discussed in detail in the course notes.

Work Location

Perform all work for this magercise in VisualAge project MageLang Magercises, package magercises.qstack.

If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name.

Tasks

Perform the following tasks:

  1. Fill in the Stack interface with the two needed methods.

  2. Do the same for the Queue interface

  3. Add all necessary methods to QStack so it can implement the two interfaces.

  4. Add a nice toString method to QStack so it will print out well.

Vector Enumeration

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and expected behavior, to demonstrate it.


Copyright © 1996-1997 MageLang Institute. All Rights Reserved.