#include <stdio.h>
#include <stdlib.h>
#define Size 20
typedef char ElementType;
typedef struct
{
ElementType data[Size];
int top;
}Stack;
int StackFull(Stack *s)
{
return (s->top==Size-1);
}
void PushStack(Stack *s, char *buf)
{
if(NULL==s || NULL==buf)
return;
while( *buf!='\0' && *buf!='^' && !StackFull(s))
{
if(*buf != ' ')
s->data[++s->top] = *buf;
++buf;
}
}
void PopStack(Stack *s)
{
if(NULL == s)
return;
while(s->top != -1)
putchar(s->data[s->top--]);
}
int main()
{
char str[Size];
Stack *s = (Stack*)malloc(sizeof(Stack));
s->top = -1;
gets(str);
PushStack(s, str);
PopStack(s);
return 0;
}
温馨提示:答案为网友推荐,仅供参考