Programming Assignment 5 - Undo-Redo

Advanced Programming II, Fall 2001


Due Date

This assignment is due by 2:00 p.m. on Thursday, 15 November.

See the assignment turn-in page (last modified on 11 September 2001) for instructions on turning in your assignment.

The Problem

Implement a simple graph-manipulator program that includes undo-redo commands. The commands understood by the program are

  1. node name - create a node with the label name. Should print an error message if a node with the label name already exists in the graph. The new node does not have an edge to any other node in the graph.

  2. edge name1 name2 - create an edge between the node with label name1 and the node with label name2; name1 need not be different than name2. If an edge already exists between name1 and name2, do nothing; if name1 or name2 don't exist, print an informative error message.

  3. print - print the nodes and edges in the current graph, with the following format:

      name name1, name2, . . .

    where name is a node's label and namei is the label of a node to which name has an edge. The information on each node should appear on one line; every node should have its information printed. The list of connected nodes should appear in alphabetical order from left to right, and the nodes should be printed in alphabetical order.

  4. undo - Undo the effects of the most recent effective node or edge command; print an error message if there is no effective command to undo. The most recent effective command undone becomes an inactive command.

  5. redo - Redo the most recent inactive command (which can only be a node or edge command); print an error message if there's no inactive command to redo. The most recent inactive command redone becomes an effective command.

Command input comes from standard-in; command output (if any) goes to standard-out; error output goes to standard-error. Each command fits on one line of input and each line of input contains at most one command.

Each node or edge command entered from the command-line deletes all inactive commands.

A name is any maximal sequence of non-space characters. Case is not significant in node labels; however node labels should be output with exactly the same case is they were input in a node command. For example, the label ALPHA is the same as the label alpha; however, if the label Alpha was input, then the label Alpha must be output. "Alphabetic order" should be extended to include the whole ASCII collating sequence.

Example

$ gm
* printThere's nothing to print.
* node red
* print
red
* edge red white
no node with label "white".
* node white
* edge red white
* print
red white
white red
* undoedge red white is the most recent effective command.
* print
red
white
* undonode white is the most recent effective command.
* print
red
* undonode red is the most recent effective command.
* print
* undo
no commands to undo.
* redonode red is the most recent inactive command.
* print
red
* redoredo node white
* node blueedge red white is gone.
* redo
no commands to redo
* print
blue
red
white
*^D
$

Testing

You're on your own.


This page last modified on 1 November 2001.