Answers for "std queue c++"

C++
1

std::queue

#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
bool is_palindrome(const std::string &s){
    std::stack<char> LIFO;
    std::queue<char> FIFO;
    for(auto &c: s){
        if(std::isalpha(c)){

            LIFO.push(std::toupper(c));
            FIFO.push(std::toupper(c));
        }
    }
    bool ans;
    while( (LIFO.size() && FIFO.size()) != 0){
        ans = (LIFO.top() == FIFO.front());
        if(!ans){
            return ans;
        }
        LIFO.pop(),FIFO.pop();
    }
    return true ;
}



int main() {
    try{
        std::string s ;
        std::cout << "Enter a string" << std::endl;
        std::cin >> s;
        std::cout << std::boolalpha << is_palindrome( s) << std::endl;
    }catch(std::exception &e){
     std::cout << e.what() << std::endl;
    }

    return 0;
}
Posted by: Guest on December-18-2021

Browse Popular Code Answers by Language