Question: Can anyone help me fix this program to make sure use stack and use STL library to check the name1 and name2 is palindrome. Thank

Can anyone help me fix this program to make sure use stack and use STL library to check the name1 and name2 is palindrome.

Thank you

stackPalindrome.h

#ifndef_STACK_PALINDROME_H #define_STACK_PALINDROME_H template class StackPalindrome { public: virtual bool isEmpty() const = 0; virtual bool push(const ItemType& newEntry) = 0; virtual bool pop() = 0; virtual ItemType peek() const = 0; }; #endif

stack.cpp

#include #include #include #include "stackPalindrome.h" using namespace std;

template class OurStack { private: stack OurStack; public: bool OurStack::isEmpty() { return Ourstack.empty(); } }; bool OurStack::push(const ItemType& newEntry) { Ourstack.push(newEntry);

if (Ourstack.top() == newEntry) return true; else return false; } bool OurStack::pop() { if (!Ourstack.empty()) { Ourstack.pop(); return true; } else return false; } ItemType OurStack::peek() { return Ourstack.top(); } bool isPalindrome(string inp_string) { OurStack char_stack; bool chckStatus = true; int string_len = (int)inp_string.length(); if (string_len > 0) { for (int i = 0; i < string_len; i++) char_stack.push(inp_string[i]); int i = 0; while (chckStatus && !char_stack.isEmpty() && (i < string_len)) { char item_stack = char_stack.peek(); char_stack.pop(); if (item_stack != inp_string[i]) chckStatus = false; else i++; } } else chckStatus = false; return chckStatus; } int main() { string name1 = "love to hoot"; string name2 = "Testing Palindrome "; if (isPalindrome(name1)) cout << " The string " << name1 << "is palindrome. " else cout << " The string " << name1 << "is not palindrome. " if (isPalindrome(name2)) cout << " The string " << name2 << "is palindrome. " else cout << " The string " << name2 << "is not palindrome. " system("pause"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!