CSC 132 Fall 2000
Lab 4
Due: end of today's lab, 5 October 2000
15 points
"Palindrome"
You will need files CharList.java, PalApplet.java and PalApplet.html from the eccentric download folder for Lab 4. Note: to download the HTML file you need to right-click then "save target as..". The CharList class is identical to Lab 3's IntList class, except the item stored in a node is a character (char) instead of an integer (int). The source code is well documented with javadoc-style comments so you can read about it here. Like IntList, CharList uses a private inner class called Node, and CharList methods provide all node and list maintenance.
The purpose of the applet is to determine whether or not an input word is a palindrome. A palindrome is a word spelled the same either backward or forward. The word will be entered in an AWT text field and stored in a linked list with one character per node, starting with the head node. The applet will then determine whether it is a palindrome by making a copy of the list in reverse order then checking the original list against the copy for equality. If the original list and its reversed copy contain the same sequence of characters, it is a palindrome otherwise not.
Your assignment is to implement the two CharList methods required to support this applet: reverse() and equals(). The methods are outlined in CharList.java. You are to fill in the details. You must implement reverse to make only one traversal of the original list.
// No preconditions or postconditions. // Returns a CharList object which is a copy of the original // ("this") object only with the nodes in reverse order. The // original list is not modified. You must do this in one // traversal of the original list. public CharList reverse() { CharList copyRev = new CharList(); // you implement. return copyRev; } // No preconditions or postconditions. // Returns true if theList stores same sequence of characters // as "this", false otherwise. public boolean equals(CharList theList) { return false; // you implement, and replace this. }
[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]
Last reviewed: 4 October 2000
Peter Sanderson (
PeteSanderson@smsu.edu )