//I am trying to use the reverse function but only get garbage when trying to print s2. How do I properly assign s2 a value in order to print it in main?
#include <iostream>
#include <string>
using namespace std;
class ch_stack {
public:
void reset() { top = EMPTY; }
void push(char c) { s[++top] = c; }
char pop() { return s[top--]; }
char top_of() const { return s[top]; }
bool empty() const { return (top == EMPTY); }
bool full() const { return (top == FULL); }
private:
enum { max_len = 100, EMPTY = -1, FULL = max_len - 1 };
char s[max_len];
int top;
};
int main()
{
void reverse(const char s1[], char s2[]);
char s1[40] = { "Reverse Me" };
char s2[40];
cout << "Original string: " << s1 << endl;
reverse(s1, s2);
cout << "\nReversed string: " << s2;
cout << endl;
system ("PAUSE");
}
void reverse(const char s1[], char s2[])
{
ch_stack s;
int i = 0;
s.reset();
if (s1 != '\0')
{
while (s1 && !s.full())
s.push(s1[i++]);
while (!s.empty())
s.pop();
}
}