Here's where I ended up...
Expand|Select|Wrap|Line Numbers
- #include <iostream.h>
- #include <cstring.h>
- const Maxstack = 5;
- int Top;
- //Prototypes
- void Push(char Stack[][50], char item);
- void Pop(char Stack[][50], char item);
- bool Empty();
- bool Full();
- void Init();
- main()
- {
- char Stack[Maxstack][50];
- //char Item[50];
- char item;
- char ans;
- ans ='y';
- string name;
- string mystack;
- int i = 0;
- while(ans=='y' || ans == 'Y')
- {
- cout<<"Enter a word: ";
- cin>>name;
- Init();
- for(i=0; i<=name.length(); i++)
- {
- mystack = name.substr(i,1);
- Push(Stack, mystack);
- Pop(Stack, item);
- cout<<item<<endl;
- }
- cout<<"\nDo you want to continue: ";
- cin>>ans;
- }
- return 0;
- }
- void Push(char Stack[][50], char item)
- {
- if(Full())
- {
- cout<<"Full";
- }
- else
- {
- strcpy(Stack[++Top], item);
- }
- //Stack[++Top] = item;
- }
- void Pop(char Stack[][50], char item)
- {
- if(Empty())
- {
- cout<<"Empty";
- //strcpy(item, "");
- }
- else
- strcpy(item, Stack[Top]);
- Top--;
- //return StackTop--];
- }
- bool Empty()
- {
- return(Top==-1);
- }
- bool Full()
- {
- return (Top+1==Maxstack);
- }
- void Init()
- {
- Top =-1;
- }