AlaminSakib

Palindrome checker using stack and queue [BJIT]

Dec 18th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool the_checker(string s)
  5. {
  6.     stack < char > stk;
  7.     queue < char > qyu;
  8.     for(int i = 0; i < s.size(); i++)
  9.     {
  10.         stk.push(s[i]);
  11.         qyu.push(s[i]);
  12.     }
  13.     while(!qyu.empty())
  14.     {
  15.         if(stk.top() != qyu.front()) return false;
  16.         else stk.pop(), qyu.pop();
  17.     }
  18.     return true;
  19. }
  20.  
  21. int main()
  22. {
  23.     string s = "racecars";
  24.     cout << the_checker(s);
  25. }
Add Comment
Please, Sign In to add comment