Advertisement
Guest User

Project 8 prob 1

a guest
Oct 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. /***************************************************
  2. Name: Jan Bansuan
  3. Date: 10-18-17
  4. Project 8: Prob 1
  5. ****************************************************/
  6. #include<iostream>
  7. #include<string>
  8. using namespace std;
  9. template<class T>
  10.  
  11.  
  12. class STACK_LIST
  13. {
  14. private: struct node
  15. {
  16. T info;
  17. node *next;
  18. };
  19. node *stack;
  20. public: STACK_LIST() { stack = NULL; }
  21. //-----------------add a node at the front of the list
  22. void pushs(T x)
  23. {
  24. node *p;
  25. p = new (node); p->info = x; p->next = NULL;
  26. if (stack == NULL)
  27. {
  28. stack = p;
  29. }
  30. else
  31. p->next = stack; stack = p;
  32. }
  33. //---------------test whether stack is empty or not
  34. bool Emptys()
  35. {
  36. if (stack == NULL)return true;
  37. else
  38. return false;
  39. }
  40. //----------------------pop the first node
  41. T pops()
  42. {
  43. node *p = stack; T x;
  44. x = stack->info;
  45. stack = stack->next;
  46. delete (p);
  47. return x;
  48. }
  49. };
  50. template<class R>
  51.  
  52. class QUEUE_LIST
  53. {
  54. private: struct node
  55. {
  56. R info;
  57. node *next;
  58. };
  59. node *front, *rear;
  60. public: QUEUE_LIST() { front = NULL; rear = NULL; }
  61. //----------add a node at the rear of the queue
  62. void pushq(R x)
  63. {
  64. node *p;
  65. p = new (node); p->info = x; p->next = NULL;
  66. if (front == NULL)
  67. {
  68. front = p; rear = p;
  69. }
  70. else
  71. {
  72. rear->next = p; rear = p;
  73. }
  74. }
  75. //-------------test whether queue is empty or not
  76. bool Emptyq()
  77. {
  78. if (front == NULL) return true;
  79. else
  80. return false;
  81. }
  82. //------------pop the first node
  83. R popq()
  84. {
  85. node *p = front; R x;
  86. x = front->info;
  87. front = front->next;
  88. delete(p);
  89. return x;
  90. }
  91. };//end class
  92.  
  93. void main()
  94. {
  95. STACK_LIST<char>S;
  96. QUEUE_LIST<char>Q;
  97. char phrase;
  98. char c1;
  99. char c2;
  100. cout << "Enter a phrase: ";
  101. cin >> phrase;
  102. for (int i = 0; i < 7; i++)
  103. {
  104. S.pushs(phrase);
  105. Q.pushq(phrase);
  106. }
  107. while (S.Emptys() != NULL)
  108. {
  109. c1 = S.pops();
  110. c2 = Q.popq();
  111. c1 = putchar(toupper(c1));
  112. c2 = putchar(toupper(c2));
  113. if (c1 != c2) break;
  114. }
  115. if (c1 = c2) cout << "Palindrome\n";
  116. else cout << "not a palindrome\n";
  117.  
  118. system("pause");
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement