Guest User

Untitled

a guest
Feb 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "ArrayQueue.h"
  4. #include "ArrayStack.h"
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. ArrayQueue queue(5);
  12. ArrayStack Stack(5);
  13.  
  14. cout << "Enqueuing 5 items...\n";
  15.  
  16. //Enqueue 5 items
  17. queue.enqueue(*"a");
  18. queue.enqueue(*"b");
  19. queue.enqueue(*"c");
  20. queue.enqueue(*"d");
  21. queue.enqueue(*"e");
  22.  
  23.  
  24.  
  25. //Dequeue and get all queue items
  26. cout << "The items in the queue were...\n";
  27. while (!queue.isEmpty())
  28. {
  29. char val;
  30. queue.dequeue(val);
  31. cout << val << " " ;
  32. }
  33. cout << endl;
  34.  
  35.  
  36.  
  37.  
  38. string word;
  39. char nextChar;
  40. cout << "Please enter a word.\n"; //Has the user enter a string
  41. cin >> word;
  42.  
  43. int length = word.length(); //Finds the length of the string
  44.  
  45. cout << "The length of your word is : " << length << endl; //Outputs the length of the string entered
  46.  
  47. for (int i = 1; i < length; i++) //Puts each character of the string into a queue and a stack
  48. {
  49. nextChar = i;
  50. queue.enqueue(nextChar);
  51. Stack.Push(nextChar);
  52. }
  53.  
  54. bool charactersEqual = true;
  55.  
  56. while (!queue.isEmpty() && charactersEqual == true) //compares the stack and queue
  57. {
  58. char theFront, theTop;
  59. queue.getFront();
  60. Stack.getTop();
  61.  
  62. if (theFront == theTop)
  63. {
  64. queue.dequeue(nextChar);
  65. Stack.Pop(nextChar);
  66. }
  67. else
  68. {
  69. charactersEqual = false;
  70. }
  71. }
  72.  
  73. if (charactersEqual == true)
  74. {
  75. cout << "Palindrome";
  76. }
  77. else
  78. {
  79. cout << "Not a palindrome";
  80. }
  81. return 0;
  82. }
Add Comment
Please, Sign In to add comment