Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include "ArrayQueue.h"
- #include "ArrayStack.h"
- using namespace std;
- int main()
- {
- ArrayQueue queue(5);
- ArrayStack Stack(5);
- cout << "Enqueuing 5 items...\n";
- //Enqueue 5 items
- queue.enqueue(*"a");
- queue.enqueue(*"b");
- queue.enqueue(*"c");
- queue.enqueue(*"d");
- queue.enqueue(*"e");
- //Dequeue and get all queue items
- cout << "The items in the queue were...\n";
- while (!queue.isEmpty())
- {
- char val;
- queue.dequeue(val);
- cout << val << " " ;
- }
- cout << endl;
- string word;
- char nextChar;
- cout << "Please enter a word.\n"; //Has the user enter a string
- cin >> word;
- int length = word.length(); //Finds the length of the string
- cout << "The length of your word is : " << length << endl; //Outputs the length of the string entered
- for (int i = 1; i < length; i++) //Puts each character of the string into a queue and a stack
- {
- nextChar = i;
- queue.enqueue(nextChar);
- Stack.Push(nextChar);
- }
- bool charactersEqual = true;
- while (!queue.isEmpty() && charactersEqual == true) //compares the stack and queue
- {
- char theFront, theTop;
- queue.getFront();
- Stack.getTop();
- if (theFront == theTop)
- {
- queue.dequeue(nextChar);
- Stack.Pop(nextChar);
- }
- else
- {
- charactersEqual = false;
- }
- }
- if (charactersEqual == true)
- {
- cout << "Palindrome";
- }
- else
- {
- cout << "Not a palindrome";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment