行编辑程序

#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 != '
'){
		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();
}

原文地址:https://www.cnblogs.com/JsonZhangAA/p/5459649.html