Queue and Stack: Comparing help!!! (palindrome)
This may be a little long, but please bear with me. I really need help on this.
I have excluded my header files for space (as you can tell probably whats in them anyway, if you need them let me know)
Code:
//----------------------------------------------------------------------
// IMPLEMENTATION FILE (Queue.cxx)
// This module exports an ADT for a bounded queue of ItemType.
// The maximum queue length is MAX_LENG.
// Queue representation: a ring buffer in a vector of
// size MAX_LENG + 1
//----------------------------------------------------------------------
#include <iostream.h>
#include "queue.h"
const int VEC_SIZE = MAX_LENG + 1;
// Private members of class:
// int data[MAX_LENG+1]; // Vector representing the queue
// int front; // (Subscript of queue front) - 1
// int rear; // Subscript of queue rear
//
// NOTE: At all times, at least one element of the data vector
// remains unused
void Queue::MakeEmpty()
//.................................................................
// Poat: front and rear have been reset to the empty state
{
front = rear = VEC_SIZE - 1;
}
Queue::Queue()
//..................................................................
// Constructor
// POST: front == 0 && rear == 0
//..................................................................
{
front = rear = VEC_SIZE - 1;
}
bool Queue::IsEmpty() const
//..................................................................
// POST: FCTVAL == (rear == front)
//..................................................................
{
return (rear == front);
}
bool Queue::IsFull() const
//..................................................................
// POST: FCTVAL == ((rear + 1) MOD VEC_SIZE == front)
//..................................................................
{
return ((rear + 1) % VEC_SIZE == front);
}
void Queue::Enqueue(ItemType newItem)
//..................................................................
// PRE: (rear + 1) MOD VEC_SIZE != front
// && Assigned(newItem)
// POST: rear == (rear<entry> + 1) MOD VEC_SIZE
// && data[rear] == newItem
//..................................................................
{
rear = (rear + 1) % VEC_SIZE;
data[rear] = newItem;
}
void Queue::Dequeue(ItemType& itemInQueue)
//..................................................................
// PRE: rear != front
// POST: front == (front<entry> + 1) MOD VEC_SIZE
//..................................................................
{
front = (front + 1) % VEC_SIZE;
itemInQueue = data[front];
}
void Queue::PrintFandR()
{
cout << "F: " << front << endl;
cout << "R: " << rear << endl;
cout << endl << endl;
}
//IMPLEMENTATION FILE FOR STACK (STACK.CXX)
#include "stack.h"
StackType::StackType( )
//------------------------------------------------
// Default Constructor
//------------------------------------------------
{
top = -1;
}
void StackType::MakeEmpty( )
//---------------------------------------------------
// PRE: None.
// POST: Stack is empty.
//---------------------------------------------------
{
top = -1;
}
bool StackType::IsEmpty( ) const
//---------------------------------------------------
// PRE: Stack has been initialized.
// POST: Function value = (stack is empty)
//---------------------------------------------------
{
return ( top == -1 );
}
bool StackType::IsFull( ) const
//---------------------------------------------------
// PRE: Stack has been initialized.
// POST: Function value = (stack is full)
//---------------------------------------------------
{
return ( top == MAX_ITEMS-1);
}
void StackType::Push ( ItemType newItem )
//------------------------------------------------------
// PRE: Stack has been initialized and is not full.
// POST: newItem is at the top of the stack.
//------------------------------------------------------
{
top++;
items[top] = newItem;
}
void StackType::Pop ( ItemType& item )
//------------------------------------------------------
// PRE: Stack has been initialized and is not empty.
// POST: Top element has been removed from stack.
// item is a copy of removed element.
//------------------------------------------------------
{
item = items[top];
top--;
}
//IMPLEMENTATION FILE FOR ITEMTYPE
#include "ItemType.h"
void ItemType::ReadInStackQueue(ifstream inFile)
{
char c;
inFile >> c;
}
void ItemType::ReadCharacter(ifstream& inFile)
{
inFile >> newItem;
}
void ItemType::WriteOut(ofstream& outFile)
{
outFile << newItem;
}
/////MAIN!!!!!
#include "stack.h"
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
inFile.open("in.data");
outFile.open("out.data");
Queue q;
StackType s;
ItemType data;
ItemType copy;
int counter = 0;
int mismatch = 0;
char ch;
data.ReadCharacter(inFile);
copy = data;
while (inFile)
{
s.Push(data);
q.Enqueue(copy);
data.ReadCharacter(inFile);
copy = data;
counter++;
}
while (counter > 0)
{
s.Pop(data);
q.Dequeue(copy);
if (copy == data)
mismatch++;
copy.WriteOut(outFile);
counter--;
}
if (mismatch > 0)
outFile << ": >>> This is not a palindrome!" << endl;
else
outFile << ": >>> This is a palindrome!" << endl;
return 0;
}
The part in red i cannot due as it gives me an error. But I need to pop an element from the top of the stack, dequeue, and then compare those two till it is done to figure out if it is a palindrome or not. Any help I would GREATLY appreciate. Thank you,
Aaron