Project 2 - A Text Editor/Analyzer
Due - Thursday, April 20, 2006
The goal of this project is to give you experience using linked
lists and recursion. You will write a program that stores a
phrase as a linked list of strings. Your program will allow the
user to perform the following editing operations:
- Insert a word
- Remove a word
- Move cursor forward 1 word
- Move cursor back 1 word
- Reverse the phrase
- Recursively count the number of repeated occurrences of a word
- Search and replace
Implementation Requirements and Hints
- Your user interface will have a main control loop that will
(1) allow the user to select an operation, (2) perform the
operation, and (3) print the resulting phrase.
- You will extend your LinkedList implementation to include a
cursor. The cursor is simply a pointer to a particular
node in the list. If the user asks to move the cursor forward,
the pointer will advance to the next node in the list; if the
user asks to move the cursor backward it will retreat to the
previous node in the list.
- You will need to modify your LinkedList print function to
indicate the location of the cursor. For example, you might
print "cs is^ fun" to indicate that the cursor is on the string
"is".
- If the user chooses to perform an insert, the new word
should be inserted immediately after the node indicated by the
cursor. If the user chooses to perform a delete, the node
indicated by the cursor should be deleted.
- Using a singly linked list, the move cursor backward
operation will have O(n) complexity. That's okay, but consider
doing the extra credit portion!
- You do not need to reverse the phrase letter-by-letter. For
example, reversing the phrase "cs is fun" would yield "fun is
cs".
- The search and replace operation will ask for the
search string and the replace string. It will then replace all
instances of the search string with the replace string.
- Make sure to handle all special cases, for example the case
when the user tries to advance a cursor that is already at the
last node of the list.
Extra Credit Opportunity
For extra credit, implement and use a doubly linked list for this
assignment rather than the singly linked list. Note that the
doubly linked list will actually make some of the operations
easier to implement.
Due 2:40PM Thursday April 20, 2006
- Complete and submit your working code.
- Make sure that each function is well documented. Your documentation should specify the type and function of the input parameters and output.
- Run your program on a variety of inputs ensuring that all error conditions are handled correctly.
Note: No portion of your code may be copied from any other
source including another text book, a web page, or another
student (current or former). You must provide citations for any
sources you have used in designing and implementing your program.
Sami Rollins