栈的应用,表达式转换。输入结束后为什么输不出来栈里的元素

#include
using namespace std;
#define maxsize 20
typedef struct
{
char *base;
char *top;
int stacksize;
}SqStack;

bool InitStack(SqStack &S)
{
S.base = new char[maxsize];
if (!S.base) return false;
S.top = S.base;
S.stacksize = maxsize;
return true;
}

bool Push(SqStack &S, char e)
{
if (S.top - S.base == S.stacksize)
return false;
*S.top = e;
S.top++;
return true;
}

bool Pop(SqStack &S, char &e)
{
if (S.top == S.base)
return false;
--S.top;
e = *S.top;
return true;
}

char GetTop(SqStack S)
{
char e;
if (S.top == S.base)
return false;
e = *(S.top - 1);
return e;
}

char bijiao(char a, char b)
{
if (a == '#' || a == '(')
{
if (b == ')') return '=';
return '<';
}
if (a == '+' || a == '-')
{
if (b == '*' || b == '/' || b == '(')
return '<';
else return '>';
}
if (a == '*' || a == '/')
{
if (b == '(')
return '<';
else return '>';
}
if (a == ')')
return '<';
}

bool StackEmpty(SqStack &S)
{
if (S.top == S.base)
return true;
else
return false;
}
int main()
{
SqStack S;
InitStack(S);

Push(S, '#');
int t;
char ch, k, m, n, p;
cin >> ch;

for (; ch != '\n';cin>>ch)
{
    if (ch >= '0'&&ch <= '9') { t = ch - '0'; cout << t << ' '; }
    else
    {
        switch (bijiao(GetTop(S), ch))
        {
        case '<':Push(S, ch); break;
        case '>':while (GetTop(S) != '#')
                {
                     if (GetTop(S) != '(')
                     {
                         Pop(S, m);
                         cout << m << ' ';
                     }
                     else Pop(S, n);
                } break;
        }
    }
}

while (!StackEmpty(S))
{
    if (GetTop(S) != '#')
    {
        Pop(S, p);
        cout << p;
    }
}
return 0;

}

cin>>ch;无法接受到\n,改为

另外,栈用的也有问题,看注释

#include<iostream>
using namespace std;
#define maxsize 20
typedef struct
{
    char *base;
    char *top;
    int stacksize;
}SqStack;
bool InitStack(SqStack &S)
{
    S.base = new char[maxsize];
    if (!S.base) return false;
    S.top = S.base;
    S.stacksize = maxsize;
    return true;
}
bool Push(SqStack &S, char e)
{
    if (S.top - S.base == S.stacksize)
        return false;
    S.top++;        //先移动栈顶指针,此时栈顶为空,把e的值栈顶
    *S.top = e;
    return true;
}
bool Pop(SqStack &S, char &e)
{
    if (S.top == S.base)
        return false;
    e = *S.top;    //先把栈顶元素给e,然后栈顶减一
    --S.top;
    return true;
}
char GetTop(SqStack S)
{
    char e;
    if (S.top == S.base)
        return false;
    e = *S.top;     //把栈顶元素直接给e
    return e;
}
char bijiao(char a, char b)
{
    if (a == '#' || a == '(')
    {
        if (b == ')') return '=';
        return '<';
    }
    if (a == '+' || a == '-')
    {
        if (b == '*' || b == '/' || b == '(')
            return '<';
        else return '>';
    }
    if (a == '*' || a == '/')
    {
        if (b == '(')
            return '<';
        else return '>';
    }
    if (a == ')')
        return '<';
}
bool StackEmpty(SqStack &S)
{
    if (S.top == S.base)
        return true;
    else
        return false;
}
int main()
{
    SqStack S;
    InitStack(S);
    Push(S, '#');
    int t;
    char ch, k, m, n, p;
    ch=getchar();       //cin>>不能接受到\n,改用getchar
    for (; ch != '\n'; ch=getchar()) //同上
    {
        if (ch >= '0'&&ch <= '9') {
            t = ch - '0'; 
            cout << t << ' ';
        }
        else
        {
            switch (bijiao(GetTop(S), ch))
            {
            case '<':Push(S, ch); break;
            case '>':while (GetTop(S) != '#')
            {
                if (GetTop(S) != '(')
                {
                    Pop(S, m);
                    cout << m << ' ';
                }
                else Pop(S, n);
            } break;
            }
        }
    }

    while (!StackEmpty(S))
    {
        if (GetTop(S) != '#')
        {
            Pop(S, p);
            cout << p;
        }
        else                //如果得到#,可以弹出#,然后才能确保栈空,结束循环
            Pop(S, p);
    }
    return 0;
}

你的代码就不看了,看我之前的回答
https://ask.csdn.net/questions/703345

在pta上都不符合测试点。。
7-1 表达式转换 (25 分)
算术表达式有前缀表示法、中缀表示法和后缀表示法等形式。日常使用的算术表达式是采用中缀表示法,即二元运算符位于两个运算数中间。请设计程序将中缀表达式转换为后缀表达式。

输入格式:
输入在一行中给出不含空格的中缀表达式,可包含+、-、*、\以及左右括号(),表达式不超过20个字符。

输出格式:
在一行中输出转换后的后缀表达式,要求不同对象(运算数、运算符号)之间以空格分隔,但结尾不得有多余空格。
#include
using namespace std;
#define maxsize 20
typedef struct
{
char base;
char *top;
int stacksize;
}SqStack;
bool InitStack(SqStack &S)
{
S.base = new char[maxsize];
if (!S.base) return false;
S.top = S.base;
S.stacksize = maxsize;
return true;
}
bool Push(SqStack &S, char e)
{
if (S.top - S.base == S.stacksize)
return false;
S.top++; //先移动栈顶指针,此时栈顶为空,把e的值栈顶
*S.top = e;
return true;
}
bool Pop(SqStack &S, char &e)
{
if (S.top == S.base)
return false;
e = *S.top; //先把栈顶元素给e,然后栈顶减一
--S.top;
return true;
}
char GetTop(SqStack S)
{
char e;
if (S.top == S.base)
return false;
e = *S.top; //把栈顶元素直接给e
return e;
}
char bijiao(char a, char b)
{
if (a == '#' || a == '(')
{
if (b == ')') return '=';
return '<';
}
if (a == '+' || a == '-')
{
if (b == '
' || b == '/' || b == '(')
return '<';
else return '>';
}
if (a == '*' || a == '/')
{
if (b == '(')
return '<';
else return '>';
}
if (a == ')')
return '<';
}
bool StackEmpty(SqStack &S)
{
if (S.top == S.base)
return true;
else
return false;
}
int main()
{
SqStack S;
InitStack(S);
Push(S, '#');
int t;
char ch, m, n, p;
ch = getchar();

for (; ch != '\n'; ch = getchar())
{
if (ch >= '0'&&ch <= '9') {
t = ch - '0';
cout << t << ' ';
}
else
{
switch (bijiao(GetTop(S), ch))
{
case '<':Push(S, ch); break;
case '>':while (GetTop(S) != '#')
{
if (GetTop(S) != '(')
{
Pop(S, m);
cout << m << ' ';
}
else Pop(S, n);
} break;
}
}
}

while (GetTop(S) != '#')
{
    Pop(S, p);
    if (GetTop(S) != '#')
        cout << p << ' ';
    else
        cout << p;
}
return 0;

}