> For the complete documentation index, see [llms.txt](https://kkishan114.gitbook.io/30-days-of-code/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kkishan114.gitbook.io/30-days-of-code/index/day-18-queues-and-stacks.md).

# Day 18: Queues and Stacks

### Problem Link <a href="#problem" id="problem"></a>

* [x] [**HackerRank Problem Link**](https://www.hackerrank.com/challenges/30-queues-stacks/problem)

### Solution

* [x] **In C++ Language**

{% code title="QueuesAndStacks.cpp" %}

```cpp
#include <iostream>
#include <stack>
#include <queue>

using namespace std;

class Solution {
    //Write your code here
    stack<char> stk;
    queue<char> que;
    public:
    
 char c;
    
    void pushCharacter(char ch) 
 {
        stk.push(ch);
    }
        char popCharacter() 
 {
        c = stk.top();
        stk.pop();
        return c;
    }
    void enqueueCharacter(char ch) 
 {
        que.push(ch);
    }
    char dequeueCharacter() 
 {
        c = que.front();
        que.pop();
        return c;
    }
};

int main() {
    // read the string s.
    string s;
    getline(cin, s);
    
  	// create the Solution class object p.
    Solution obj;
    
    // push/enqueue all the characters of string s to stack.
    for (int i = 0; i < s.length(); i++) {
        obj.pushCharacter(s[i]);
        obj.enqueueCharacter(s[i]);
    }
    
    bool isPalindrome = true;
    
    // pop the top character from stack.
    // dequeue the first character from queue.
    // compare both the characters.
    for (int i = 0; i < s.length() / 2; i++) {
        if (obj.popCharacter() != obj.dequeueCharacter()) {
            isPalindrome = false;
            
            break;
        }
    }
    
    // finally print whether string s is palindrome or not.
    if (isPalindrome) {
        cout << "The word, " << s << ", is a palindrome.";
    } else {
        cout << "The word, " << s << ", is not a palindrome.";
    }
    
    return 0;
}
```

{% endcode %}
