Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions