Hi, i have this program that i made but my code really stinks not cause the sintaxis code but the functionality is ugly, look the program recive a string like this madamxmadam an then start to push the data into S so when find a x start to compare the pop() function in s with the rest of the string x but... i have problems for example if i put "exee" the programm doesnt do anything or if i put madamxmadam i have a this messega like the message on windows xp "temp.exe has encountered a problem and needs to close. We are sorry for the inconvenience." the program runs but before the message pres any key to continue appears then the error comes...

i really apreciate if you have a better idea for this code... like i dont made a anthor string a copy... or idont.... please i really need help...
Code:
#include <iostream.h>
#include<string.h>

template <class T>
class stack
{
	private:
		T *S;
		int length;
		int top;
	public:
		stack (int inilength);
		~stack();
		palx(T *x);
		int empty();
		push(T x);
		T pop();
};

template <class T>
stack<T>::stack(int inilength)
{
	length=inilength;
	S=new T[length];
	top=-1;
}

template <class T>
stack<T>::~stack()
{
	delete S;
}

template <class T>
int stack<T>::empty()
{
	if(top==-1)
	{ return 1; }
	else return 0;
}

template <class T>
stack<T>::push(T x)
{
	top++;
	S[top]=x;
}

template <class T>
T stack<T>::pop()
{
	
	if (empty()==-1)
	{ cout<<"Error Underflow"; }
	else 
	{
			top--;
	return S[top+1];
	}

}

template <class T>
stack<T>::palx(T *x)
{
	int j=0;
	int str=strlen(x);
	char comp;

	if(j<str)
	{
		while(x[j]!='x')
		{
			push(x[j]);
			j++;
		}
		
		if(x[j]=='x')
		{
			while(top>-1)
			{
				j++;
				comp=pop();
				if(comp!=x[j])
					{cout<<"No is not";top=-1;}
				else if((j==str-1) && (top<0))
				{ cout<< "yes it is"; }
			}
		}
	}
}


void main()
{
	
	char *palindrome;
	palindrome = new char(50);
	stack<char> *nueva;
	nueva = new stack<char>(50);
	cout<<"Dame un disque palindrome: "<<endl;
	cin>>palindrome;
	nueva->palx(palindrome);
	delete nueva;
}