#include <iostream>
#include <string>
using namespace std;
template <class T>
class stack {
public:
stack(int size = 100) : max_len(size), top(EMPTY), s(new T[size]) { }
~stack() { delete []s;}
void reset() { top = EMPTY;}
void push(T c) { s[++top] = c;}
T pop() { return s[top--];}
bool empty() const { return top ==EMPTY; }
bool full() const { return top == max_len -1;}
private:
enum {EMPTY = -1};
T* s;
int max_len;
int top;
};
int main()
{
stack<char> s;
string c = "My name is Nilkanth";
cout<<"\n The original string is: \n";
for( int i=0;i<=c.length();i++)
{
s.push(c[i]);
cout<<c[i];
}
cout<<"\n The reversed string is: \n";
for(int i=0;i<=c.length();i++)
{
cout<<s.pop();
}
}
No comments:
Write comments