Question: ( CSCI 2 5 1 ) Project 2 : Implement and Apply Stack and Queue Total Grading Points: 1 0 0 Purpose and Project Description:
CSCI Project : Implement and Apply Stack and Queue
Total Grading Points:
Purpose and Project Description:
The purpose for this project is to reinforce the knowledge from Chapter of the online course
textbook zyBooks Students will practice how to implement stack and queue data structures
using list ADT; for instance, ArrayList. Students will also apply a stack and a queue in practical
implementation; for instance, to check if a string is a palindrome or not. The implementation
can be done in either Java or C programming language.
Tasks:
Use ArrayList to implement MyStack class which define the data structure that
has LastInFirstOut property points
Use ArrayList to implement MyQueue class which define the data structure that
has FirstInFirstOut property points
Write a function public static Boolean isPalindrome String sentence points
This function returns true if sentence is a palindrome; false otherwise.
Provided Template files:
Three template files are given in either Java or Cthat is CSCIProjectTwo, MyStack and
MyQueue Students should add necessary comments to all files and implement all
functionalities in the given files. No extra functions can be added. No function name can
be changed. Do not modify the contents of the main method in CSCIProjectTwo file.
CSCIProjectTwo: Use MyStack and MyQueue to write a project that checks if a sentence is palindrome
@author Your name
@version Date
import java.util.Scanner;
public class CSCIProjectTwo
public static void mainString args
Scanner input new ScannerSystemin;
String sentence;
String again;
do
System.out.printlnEnter a sentence, I will tell you if it is a palindrome: ;
sentence input.nextLine;
ifisPalindromesentence
System.out.println sentence is a palindrome!";
else
System.out.println sentence is not a palindrome!";
System.out.printlnDo you want another test YES or NO: ;
again input.nextLine;
whileagainequalsIgnoreCaseYES;
isPalindrome returns true if the given String is a palindrome
@
public static boolean isPalindromeString sentence
You implement this
declare a MyStack s
MyStack s new MyStack;
declare a MyQueue q
MyQueue q new MyQueue;
forint i ; i sentence.length; i
if ith character in sentence is a letter
convert to upper case and push it into s and q
whilesisEmpty
If stack is not empty
if the front of the queue does not match the top of stack
return false
if CharacterisLettersentencecharAti
char c Character.toUpperCasesentencecharAti;
spushc;
qpushc;
pop out top of the stack and front of the queue
return true;
class MyQueue implemented using ArrayList. The index element is the front of the queue
The last element of the queue has index tail
@author Your Name
@version Date
import java.util.ArrayList;
public class MyQueue
private ArrayList list; hold the elements in queue
private int tail; index of the last element in queue
constructor construct an empty queue
public MyQueue
isEmpty return true if the queue is empty; false otherwise
@return true if the queue is empty; false otherwise
public boolean isEmpty
size return the size of the queue
@return the number of elements in queue
public int size
peek return the front element of the queue
@return the front element of the queue. If the queue is empty, return null
public E peek
pop remove the front element of the queue
public void pop
push push a new element to the queue
public void pushE item
class MyStack: A stack class implemented by using ArrayList
All stack elements are stored in an ArrayList. The top element has index top
@author Your Name
@version Date
import java.util.ArrayList;
public class MyStack
private ArrayList list; used to store elements in stack
private int top; the index of top element
constructor construct an empty stack
public MyStack
class MyStack: A stack class implemented by using
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
