Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Stack.h"
- #include <iostream>
- #include <string>
- #include <cstring>
- using namespace std;
- int main()
- {
- int count = 0;
- int len;
- string w;
- char a, c;
- cout << "Please enter a word\n";
- getline(cin, w);
- len = w.len() + 1;
- char * arr = new char[len];
- strcpy(arr, w.c_str());
- Stack palindrome(len);
- while(count <= (len - 1))
- {
- c = arr[count];
- palindrome.push(c);
- count++;
- }
- count = 0;
- while(count <= (len - 1))
- {
- palindrome.pop(a);
- if(a != arr[count])
- {
- cout << "The string is not a palindrome\n";
- return 0 ;
- }
- count++;
- }
- cout << "The string is a palindrome\n";
- delete [ ] arr;
- return 0;
- }
- }
- #include "Stack.h"
- #include <string>
- Stack::Stack(int len)
- {
- stackArray = new char[len];
- stackSize = len;
- top = -1;
- }
- Stack::~Stack()
- {
- delete [] stackArray;
- }
- void Stack::push(char str)
- {
- top++;
- stackArray[top] = str;
- }
- void Stack::pop(char &str)
- {
- if(isEmpty())
- {
- cout <<"No string\n";
- }
- else
- {
- str = stackArray[top];
- top--;
- }
- }
- bool Stack::isEmpty() const
- {
- bool status;
- if(top == -1)
- status = true;
- else
- status = false;
- return status;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement