|
-
May 7th, 2012, 11:32 AM
#1
left brace error '{'
hello can someone help me out to get this error done
PHP Code:
#include<iostream>
#include<assert.h>
#include<cstdio>
#include<cassert>
using namespace std;
template<class Type>
class stackType
{
public:
const stackType<Type>& operator=(const stackType<Type>&);
void initializeStack();
bool isEmptyStack();
bool isFullStack();
void destroyStack();
void push(const Type& newItem);
Type top();
void pop();
stackType(int stackSize = 100);
stackType(const stackType<Type>& otherStack);
~stackType();
private:
int maxStackSize;
int stackTop; // variable to point to the top of the stack
Type *list;
void copyStack(const stackType<Type>& otherStack);
};
template<class Type>
void stackType<Type>::initializeStack()
{
stackTop = 0;
}
template<class Type>
void stackType<Type>::destroyStack()
{
stackTop = 0;
}
template<class Type>
bool stackType<Type>::isFullStack()
{
return(stackTop == maxStackSize);
}
template<class Type>
bool stackType<Type>::isEmptyStack()
{
return(stackTop == 0);
}
template<class Type>
void stackType<Type>::push(const Type& newItem)
{
if(!isFullStack())
{
list[stackTop] = newItem;
stackTop++;
}
else
cout<<"Cannot add to a full stack."<<endl;
}
template<class Type>
Type stackType<Type>::top()
{
assert(stackTop != 0);
return list[stackTop - 1];
}
template<class Type>
void stackType<Type>::pop()
{
if(!isEmptyStack())
stackTop--;
else
cout<<"Cannot remove from an empty stack."<<endl;
}
template<class Type>
void stackType<Type>::copyStack(const stackType<Type>& otherStack)
{
delete [] list;
maxStackSize = otherStack.maxStackSize;
stackTop = otherStack.stackTop;
list = new Type[maxStackSize];
assert(list != NULL);
for(int j = 0; j < stackTop; j++)
list[j] = otherStack.list[j];
}
template<class Type>
stackType<Type>::stackType(int stackSize)
{
if(stackSize <= 0)
{
cout<<"The size must be positive!"<<endl;
maxStackSize = 100;
}
else
maxStackSize = stackSize;
stackTop = 0;
list = new Type[maxStackSize];
assert(list != NULL);
}
template<class Type>
stackType<Type>::~stackType()
{
delete [] list;
}
template<class Type>
stackType<Type>::stackType(const stackType<Type>& otherStack)
{
list = NULL;
copyStack(otherStack);
}
template<class Type>
const stackType<Type>& stackType<Type>::operator=(const stackType<Type>& otherStack)
{
if(this != &otherStack)
copyStack(otherStack);
return *this;
template<class Type>
class queueType
{
public:
const queueType<Type>& operator=(const queueType<Type>&);
bool isEmptyQueue();
bool isFullQueue();
void initializeQueue();
void destroyQueue();
Type front();
Type back();
void addQueue(const Type& queueElement);
void deleteQueue();
queueType(int queueSize = 100);
queueType(const queueType<Type>& otherQueue);
~queueType();
private:
int maxQueueSize;
int count;
int queueFront;
int queueRear;
Type *list;
};
template<class Type>
const queueType<Type>& queueType<Type>:: operator=(const queueType<Type>& otherQueue)
{
if(this != &otherQueue)
{
delete [] list;
maxQueueSize = otherQueue.maxQueueSize;
count = otherQueue.count;
queueRear = otherQueue.queueRear;
queueFront = otherQueue.queueFront;
list = new Type[maxQueueSize];
assert(list != NULL);
for(int j = queueFront; j < count; j = (j+1)%maxQueueSize)
list[j] = otherQueue.list[j];
}
return *this;
}
template<class Type>
bool queueType<Type>::isEmptyQueue()
{
return (count == 0);
}
template<class Type>
bool queueType<Type>::isFullQueue()
{
return (count == maxQueueSize);
}
template<class Type>
void queueType<Type>::initializeQueue()
{
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
}
template<class Type>
void queueType<Type>::destroyQueue()
{
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
}
template<class Type>
Type queueType<Type>::front()
{
assert(!isEmptyQueue());
return list[queueFront];
}
template<class Type>
Type queueType<Type>::back()
{
assert(!isEmptyQueue());
return list[queueRear];
}
template<class Type>
void queueType<Type>::addQueue(const Type& newElement)
{
if(!isFullQueue())
{
queueRear = (queueRear + 1) % maxQueueSize;
count++;
list[queueRear] = newElement;
}
else
cerr<<"Cannot add to a full queue."<<endl;
}
template<class Type>
void queueType<Type>::deleteQueue()
{
if(!isEmptyQueue())
{
count--;
queueFront = (queueFront + 1) % maxQueueSize;
}
else
cerr<<"Cannot remove from an empty queue."<<endl;
}
template<class Type>
queueType<Type>::queueType(int queueSize)
{
if(queueSize <= 0)
{
cerr<<"invalid size of array"<<endl;
maxQueueSize = 100;
}
else
maxQueueSize = queueSize;
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
list = new Type[maxQueueSize];
assert(list != NULL);
}
template<class Type>
queueType<Type>::queueType(const queueType<Type>& otherQueue)
{
delete [] list;
maxQueueSize = otherQueue.maxQueueSize;
count = otherQueue.count;
queueRear = otherQueue.queueRear;
queueFront = otherQueue.queueFront;
list = new Type[maxQueueSize];
for(int j = queueFront; j < count; j = (j+1)%maxQueueSize)
list[j] = otherQueue.list[j];
}
template<class Type>
queueType<Type>::~queueType()
{
delete [] list;
}
int main()
{
string word;
bool found=true;
cout<<"Enter a word ..\"stop\" to stop the program. "<<endl;
cin>>word;
while(word != "stop")
{
stackType<char> s1(word.length());
queueType<char> q1(word.length());
for(int i=0; i < word.length();i++)
{
s1.push(word[i]);
q1.addQueue(word[i]);
found=true;
}
while(!q1.isEmptyQueue()&& found)
{
if(q1.front()==s1.top())
{
q1.deleteQueue();
s1.pop();
}
else
found=false;
}
if (found){
cout<<"The word is PALINDROME."<<endl;
else
cout<<"The word is not PALINDROME."<<endl;
cout<<"Enter a word ..\"stop\" to stop the program. "<<endl;
cin>>word;}
return 0;}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|