Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab1;
- import java.io.IOException;
- import java.util.ArrayList;
- public class Languages
- {
- ArrayList<String> items;
- public void intializeValues(String fileName) throws IOException
- {
- items = TextReader.readFile(fileName);
- }
- public boolean L5(String inputValue)
- {
- Stack_LinkedList<String> stackLL = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackL5F = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackL5R = new Stack_LinkedList<String>();
- ArrayList<String> temp = new ArrayList<String>();
- boolean verdict = false;
- for (int i = 0; i < inputValue.length(); i++)
- {
- temp.add(inputValue.substring(i, i + 1));
- }
- if ((temp.size() % 2) != 0)
- {
- for (int k = 0; k < (temp.size() / 2); k++)
- {
- stackL5F.push(temp.get(k));
- }
- for (int j = temp.size() - 1; j > (temp.size() / 2); j--)
- {
- stackL5R.push(temp.get(j));
- }
- } else if (temp.size() % 2 == 0)
- {
- for (int k = 0; k < (temp.size() / 2); k++)
- {
- stackL5F.push(temp.get(k));
- }
- for (int j = temp.size() - 1; j > (temp.size() / 2 - 1); j--)
- {
- stackL5R.push(temp.get(j));
- }
- }
- if (stackL5F.isEmpty() == true && stackL5R.isEmpty() == true)
- {
- verdict = true;
- } else
- {
- while (stackL5F.isEmpty() == false && stackL5R.isEmpty() == false)
- {
- if (stackL5F.peek().equals(stackL5R.peek()))
- {
- stackL5F.pop();
- stackL5R.pop();
- } else
- {
- verdict = false;
- break;
- }
- verdict = true;
- }
- }
- return verdict;
- }
- ///////////////////////////////////////////////////////////////////
- public boolean L4(String inputValue)
- {
- Stack_LinkedList<String> stackLL = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackL4 = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackTemp = new Stack_LinkedList<String>();
- boolean verdict = false;
- String inputString = "";
- boolean incorrectValue = false;
- inputString = inputValue.substring(0) + inputValue.substring(0);
- for (int j = 0; j < inputString.length(); j++)
- {
- String values = inputString.substring(j, j + 1);
- if (values.equals("A") == false && values.equals("B") == false)
- {
- verdict = false;
- incorrectValue = true;
- break;
- } else
- {
- stackLL.push(values);
- }
- }
- while (stackLL.isEmpty() == false && incorrectValue == false)
- {
- stackL4.push(stackLL.pop());
- }
- while (stackL4.isEmpty() == false && incorrectValue == false)
- {
- String tempString = "";
- while (stackL4.peek().equals("A"))
- {
- tempString = tempString + stackL4.pop();
- }
- while (stackL4.peek().equals("B"))
- {
- tempString = tempString + stackL4.pop();
- if (stackL4.isEmpty())
- {
- break;
- }
- }
- if (stackLL.isEmpty() == true)
- {
- stackLL.push(tempString);
- } else if (stackLL.isEmpty() == false
- && stackLL.peek().equals(tempString))
- {
- stackLL.pop();
- verdict = true;
- } else
- {
- verdict = false;
- break;
- }
- }
- return verdict;
- }
- ///////////////////////////////////////////////////////
- public boolean L1_RJ(String inputValue)
- {
- Stack_LinkedList<String> stackLL = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackL1A = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackL1B = new Stack_LinkedList<String>();
- boolean verdict = false;
- for (int j = 0; j < inputValue.length(); j++)
- {
- String values = inputValue.substring(j, j + 1);
- stackLL.push(values);
- }
- while (stackLL.isEmpty() == false)
- {
- if (stackLL.peek().equals("A"))
- {
- stackL1A.push(stackLL.pop());
- } else if (stackLL.peek().equals("B"))
- {
- stackL1B.push(stackLL.pop());
- } else
- {
- stackLL.pop();
- }
- }
- while (stackL1A.isEmpty() == false)
- {
- if (stackL1B.isEmpty() == true)
- {
- verdict = false;
- break;
- } else
- {
- stackL1A.pop();
- stackL1B.pop();
- }
- }
- if (stackL1A.isEmpty() == true && stackL1B.isEmpty() == true)
- {
- verdict = true;
- } else
- {
- verdict = false;
- }
- return verdict;
- }
- ///////////////////////////////////////////////
- public boolean L3(String inputValue)
- {
- Stack_LinkedList<String> stackLL = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackL3 = new Stack_LinkedList<String>();
- boolean verdict = false;
- for (int j = 0; j < inputValue.length(); j++)
- {
- String values = inputValue.substring(j, j + 1);
- stackLL.push(values);
- }
- while (stackLL.isEmpty() == false)
- {
- stackL3.push(stackLL.pop());
- }
- if (stackL3.isEmpty())
- {
- verdict = true;
- } else if (stackL3.peek().equals("A") == false)
- {
- verdict = false;
- } else
- {
- while (stackL3.peek().equals("A"))
- {
- stackLL.push(stackL3.pop());
- stackLL.push("A");
- }
- while (stackL3.peek().equals("B"))
- {
- stackLL.pop();
- stackL3.pop();
- if (stackL3.isEmpty() || stackLL.isEmpty())
- {
- break;
- }
- }
- }
- if (stackL3.isEmpty() && stackLL.isEmpty())
- {
- verdict = true;
- } else
- {
- verdict = false;
- }
- return verdict;
- }
- /////////////////////////////////////////////////////////
- public boolean L2(String inputValue)
- {
- Stack_LinkedList<String> stackLL = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackL2 = new Stack_LinkedList<String>();
- boolean verdict = false;
- for (int j = 0; j < inputValue.length(); j++)
- {
- String values = inputValue.substring(j, j + 1);
- stackLL.push(values);
- }
- while (stackLL.isEmpty() == false)
- {
- stackL2.push(stackLL.pop());
- }
- if (stackL2.isEmpty())
- {
- verdict = true;
- } else if (stackL2.peek().equals("A") == false)
- {
- verdict = false;
- } else
- {
- while (stackL2.peek().equals("A"))
- {
- stackLL.push(stackL2.pop());
- }
- while (stackL2.peek().equals("B"))
- {
- stackLL.pop();
- stackL2.pop();
- if (stackL2.isEmpty() || stackLL.isEmpty())
- {
- break;
- }
- }
- }
- if (stackL2.isEmpty() && stackLL.isEmpty())
- {
- verdict = true;
- } else
- {
- verdict = false;
- }
- return verdict;
- }
- ///////////////////////////////////////////////////
- public boolean L1(String inputValue)
- {
- // Stack stack = new Stack(inputValue.length());
- Stack_LinkedList<String> stackLL = new Stack_LinkedList<String>();
- Stack_LinkedList<String> stackL1 = new Stack_LinkedList<String>();
- boolean verdict = false;
- for (int j = 0; j < inputValue.length(); j++)
- {
- String values = inputValue.substring(j, j + 1);
- stackLL.push(values);
- }
- // stackL1 has the reverse of the inputString
- while (stackLL.isEmpty() == false)
- {
- stackL1.push(stackLL.pop());
- }
- if (stackL1.isEmpty() == true)
- {
- verdict = true;
- }
- else
- {
- if (stackL1.peek().equals("A"))
- {
- while (stackL1.isEmpty() == true)
- {
- if (stackL1.peek().equals("A"))
- {
- stackLL.push(stackL1.pop());
- } else if (stackL1.peek().equals("B"))
- {
- stackLL.pop();
- } else
- {
- verdict = false;
- break;
- }
- System.out.println(stackLL.peek());
- }
- if (stackLL.isEmpty() == true)
- {
- verdict = true;
- } else
- {
- verdict = false;
- }
- return verdict;
- } else if (stackL1.peek().equals("B"))
- {
- while (stackL1.isEmpty() == false)
- {
- if (stackL1.peek().equals("B"))
- {
- stackLL.push(stackL1.pop());
- } else if (stackL1.peek().equals("A"))
- {
- stackLL.pop();
- } else
- {
- verdict = false;
- break;
- }
- }
- if (stackLL.isEmpty() == true)
- {
- verdict = true;
- } else
- {
- verdict = false;
- }
- }
- }
- return verdict;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement