CS 112 Lab 9
More Stacks & Queues
Due Wednesday, May 7th 2008

For your eighth lab, you will use the Stack data structure that you wrote in your previous lab.
  1. Implement a text editor. Your editor will display a string of characters and a cursor. Your program will allow the user to move the cursor and modify the text using the following five operations:

    • right - move the cursor to the right one character or do nothing if at the end of the line
    • left - move the cursor to the left one character or do nothing if at the end of the line
    • rdelete n - delete n characters to the right of the cursor
    • ldelete n - delete n characters to the left of the cursor
    • insert c - insert the character c just before the cursor
    • quit - stop editing

    Your editor should repeatedly print the current line of text, and then promt the user to type in one of the commands from the keyboard.
    Use 2 stacks to store the characters - one to store the chars to the left of the cursor and one to store the chars to the right of the cursor.

  2. Implement a queue using two stacks.  Your queue should have enqueue, dequeue, and empty methods, and should store all of the data for the queue in two stacks.  You should use no other data structures than the two stacks, and should only call the push, pop, and empty methods of the stack to implement the queue.  You should also write a main program that tests your queue.,

Grading

Submission

All file(s) required for your project should be in the folder https://www.cs.usfca.edu/svn/<username>/cs112/Lab9/