行编辑程序

#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();
}

posted @   张杨  阅读(255)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示