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
stack.cpp
#include
template
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started