Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. public static boolean checkPalindrome(SLList list) {
  2. if (list == null || list.size() == 0){
  3. return true;
  4. }
  5. LibraryStack<Character> stack = new LibraryStack<>();
  6.  
  7. int n = list.size()/2;
  8. int counter = 0;
  9.  
  10.  
  11. while (counter != n){
  12. stack.push(list.removeFirst());
  13. counter++;
  14. }
  15.  
  16. if (list.size() % 2 == 1){
  17. list.removeFirst();
  18. }
  19.  
  20. while(!stack.isEmpty()){
  21. if (stack.pop().equals(list.removeFirst())){
  22. return true;
  23. }
  24. }
  25. return false;
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement