Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- import java.util.Stack;
- import java.util.Queue;
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.io.*;
- public class PhraseList {
- String p;
- String w;
- Stack revWord;
- String reverseP;
- private ArrayList<String> a= new ArrayList<String>();
- Queue<String> q = new LinkedList<String>();
- private Stack<String> wordStack;
- boolean result= true;
- public void readPhrase() throws IOException{
- Stack wordStack= new Stack<String>();
- Scanner phraseScanner= new Scanner(new File("data/phrase.txt"));
- while(phraseScanner.hasNext()){
- String p= phraseScanner.nextLine();
- a.add(p);
- }
- System.out.println(a);
- }
- public void parsePhrases(){
- for(String x: a){
- Scanner retrieveWords= new Scanner(x);
- while( retrieveWords.hasNext()){
- String m= retrieveWords.next();
- wordStack.push(m);
- q.add(m);
- System.out.println(q);
- System.out.println(wordStack);
- }
- }
- }
- public boolean isPalindrome(){
- int count = (q.size() + 1) / 2;
- int j = 0;
- while (j < count && result) {
- String w1 = q.remove();
- System.out.println(w1);
- String w2 = wordStack.pop();
- System.out.println(w2);
- if (!(w1.equals(w2))){
- result = false;
- j++;
- }
- if((w1.equals(w2))){
- result = true;
- }
- }
- return result;
- }
- public String toString(){
- return "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement