Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************
- Name: Jan Bansuan
- Date: 10-18-17
- Project 8: Prob 1
- ****************************************************/
- #include<iostream>
- #include<string>
- using namespace std;
- template<class T>
- class STACK_LIST
- {
- private: struct node
- {
- T info;
- node *next;
- };
- node *stack;
- public: STACK_LIST() { stack = NULL; }
- //-----------------add a node at the front of the list
- void pushs(T x)
- {
- node *p;
- p = new (node); p->info = x; p->next = NULL;
- if (stack == NULL)
- {
- stack = p;
- }
- else
- p->next = stack; stack = p;
- }
- //---------------test whether stack is empty or not
- bool Emptys()
- {
- if (stack == NULL)return true;
- else
- return false;
- }
- //----------------------pop the first node
- T pops()
- {
- node *p = stack; T x;
- x = stack->info;
- stack = stack->next;
- delete (p);
- return x;
- }
- };
- template<class R>
- class QUEUE_LIST
- {
- private: struct node
- {
- R info;
- node *next;
- };
- node *front, *rear;
- public: QUEUE_LIST() { front = NULL; rear = NULL; }
- //----------add a node at the rear of the queue
- void pushq(R x)
- {
- node *p;
- p = new (node); p->info = x; p->next = NULL;
- if (front == NULL)
- {
- front = p; rear = p;
- }
- else
- {
- rear->next = p; rear = p;
- }
- }
- //-------------test whether queue is empty or not
- bool Emptyq()
- {
- if (front == NULL) return true;
- else
- return false;
- }
- //------------pop the first node
- R popq()
- {
- node *p = front; R x;
- x = front->info;
- front = front->next;
- delete(p);
- return x;
- }
- };//end class
- void main()
- {
- STACK_LIST<char>S;
- QUEUE_LIST<char>Q;
- char phrase;
- char c1;
- char c2;
- cout << "Enter a phrase: ";
- cin >> phrase;
- for (int i = 0; i < 7; i++)
- {
- S.pushs(phrase);
- Q.pushq(phrase);
- }
- while (S.Emptys() != NULL)
- {
- c1 = S.pops();
- c2 = Q.popq();
- c1 = putchar(toupper(c1));
- c2 = putchar(toupper(c2));
- if (c1 != c2) break;
- }
- if (c1 = c2) cout << "Palindrome\n";
- else cout << "not a palindrome\n";
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement