My code builds but it doesnt do anything. I think I have two things wrong with my code and Im stuck on how to fix these. I think the first one is I may not be reading my string as a char correctly and my second one I think is that Im might not have used ch2 correctly in oder for me to dequeue into it.
Here's my code:
Code:#include<iostream> #include<string> #include<ctype.h> using namespace std; const int DefaultListSize = 50; typedef char Elem; class Astack { private: int top; /*Index for top element*/ int size; /*Maximum size of stack*/ Elem*listArray; /*Array holding stack elements*/ public: Astack(int sz =DefaultListSize) /*Constructor*/ {size = sz; top = 0; listArray = new Elem[sz];} ~Astack() { delete [] listArray;} /*Destructor*/ void clear() {top = 0;} bool push(const Elem& item){ if(top == size) return false; /* Stack is full*/ else {listArray [top++] = item; return true; } } bool pop(Elem& item){ /*Pop top element*/ if(top == 0) return false; else {item = listArray[--top]; return true; } } bool topValue(Elem& item) const { /*Return top element*/ if (top == 0) return false; else {item = listArray[top - 1]; return true; } } int length() const {return top;} bool IsEmpty() const {if(top == 0) return true; else return false; } }; class AQueue { private: int size; /*Maximum size of queue*/ int front; /*Index of front element*/ int rear; /*Index of rear element*/ Elem*listArray; /*Array holding queue elements*/ public: AQueue(int sz =DefaultListSize){ /*Constructor*/ size = sz + 1; rear = 0; front = 1; listArray = new Elem[size]; } ~AQueue() {delete [] listArray; } /*Destructor*/ void clear() {front = rear; } bool enqueue(const Elem& it) { if(((rear+2) % size) == front) return false; /*Full*/ rear = (rear+1) % size; /*Circular increment*/ listArray[rear] = it; return true; } bool dequeue(Elem& it) { if (length() == 0) return false; /*Empty*/ it = listArray[front]; front = (front+1) % size; /*Circular increment*/ return true; } bool frontValue(Elem& it) const { if (length() == 0) return false; /*Empty*/ it = listArray[front]; return true; } virtual int length() const { return ((rear+size) - front+1) % size; } }; int main() { Astack S; AQueue Q; string p; char ch1; char ch2; unsigned int i; cout << "Enter what you think is a Palindrome\n"; getline(cin, p); for(i = 0; i < p.length(); i++){ while((ch1 = cin.get()) != EOF){ if(ch1 != '\0') cout << ch1; if(('A' <= ch1) && (ch1 <= 'Z')){ S.push(ch1); Q.enqueue(ch1); } } } while(!S.IsEmpty()){ S.pop(ch1); Q.dequeue(ch2); cout << ch1; } if(ch1 == ch2) cout << "It is a Packed Palindrome" << endl; else cout << "It is not a Packed Palindrome" << endl; return 0; }