#include <stdio.h>
#include<string.h>
#define maxSize 128
typedef struct SqStack{
char data[maxSize];
int top;
}SqStack;
void InitStack(SqStack * S){
S->top = -1;
}
void Push(SqStack * s, char x)
{
if (s->top != maxSize - 1)
{
s->data[++(s->top)] = x;
}
else
{
printf("栈已经溢出!");
}
}
void Pop(SqStack * S, char e)
{
if (S->top != -1)
{
e = S->data[S->top];
--(S->top);
}
else{
printf("栈为空无法执行出栈操作!");
}
}
int StackEmpty(SqStack * s)
{
if (s->top == -1)
return 1;
else return 0;
}
void ClearStack(SqStack *S)
{
S->top = -1;
}
void DestoryStack(SqStack * S)
{
S->top = -1;
}
void PrintStack(SqStack * S)
{
int i = 0;
int length = S->top;
char str[maxSize];
while (S->top != -1)
{
str[i] = S->data[S->top];
S->top--;
i++;
}
printf("正确的数列为:");
int j, temp;
for (j = length, i = 0; j >= 0 && i != j; j--, i++)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
for (i = 0; i <=length; i++)
{
printf("%c", str[i]);
}
}
void LineEdit()
{
SqStack * S = new SqStack();
InitStack(S);
char ch = getchar();
while (ch != '\n'){
switch (ch){
case '#':Pop(S, ch); break;
case '@':ClearStack(S); break;
default:Push(S, ch); break;
}
ch = getchar();
}
PrintStack(S);
ClearStack(S);
if (ch != EOF) ch = getchar();
DestoryStack(S);
}
void main()
{
LineEdit();
getchar();
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话