The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Programme Palindrome

Posted by ibrar on April 03, 2001 at 4:25 PM

I am having problems creating a stack and queue. The problem is as the following:

A Palindrome is a word which reads the same both backwords and fowards. One way to check whether a word is a palindrome is to take each letter of the word one at a time and to place them onto both a stack and a queue. The letters are then read back from these structures and, if all letters match, the word is a palindrome.e.g tot.

Three seperate classes are to be designed and developed.
The first class is to be called CharStack which will have the following public methods:

CharStack() - the constructor for the class which creates an empty stack.
void pushChar(char ch) - pushes the single chracter ch onto the stack.
char popChar() - pops the top character of the stack and returns it.
void destroyStack() - removes any remaining contents of the stack.
boolean isEmptyStack() - returns True if the stack is empty, otherwise False.

The second class is to be called CharQueue and will offer the following public methods:

CharQueue() - the constructor for the class which creates an empty queue.
void addChar(char ch) - adds the single chracter ch to the queue.
char popChar() - takes the head character of the queue and returns it.
void destroyQueue() - removes any remaining contents of the queue.
boolean isEmptyQueue() - returns True if the queue is empty, otherwise False.

The final class is to be a Java application which uses the above two classes. It should allow the user to type in a word (of an unknown length) and will use the above method of checking whether that word is a palindrome and will report the results to the user. The programme should exit when # is types in.

I will be greatful if you can solve my problem by writing this programme.

thank you for your time.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us