⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 行编辑.cpp

📁 这里面包括数据结构多数的算法
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define StackSize 100	/*假定预分配的栈空间最多为100个元素 */

typedef char DataType;	/*假定栈元素的数据类型为字符 */
typedef struct
{	DataType data[StackSize];
	int top;
}SeqStack;


void InitStack(SeqStack *S)
{ /*将顺序栈置空 */
	(*S).top=-1;
}

int StackEmpty(SeqStack *S)
{
	return (*S).top==-1;
}

int StackFull(SeqStack *S)
{
	return (*S).top==StackSize-1;
}

void Push(SeqStack *S,DataType x)
{	if (StackFull(S))
	{	printf("Stack overflow");
		exit(0);					/*上溢,退出运行 */
	}
	(*S).data[++(*S).top]=x;		/*栈顶指针加1后将x进栈 */
}

DataType Pop(SeqStack *S)
{	if (StackEmpty(S))
	{	printf("Stack underflow");
		exit(0);					/*下溢,退出运行 */
	}
	return (*S).data[(*S).top--];	/*栈顶元素返回后将栈顶指针减1 */
}

DataType StackTop(SeqStack *S)
{	if (StackEmpty(S))
	{	printf("Stack is empty");
		exit(0);
	}
	return (*S).data[(*S).top];
}

void LineEdit()
{	SeqStack S;	char ch,line[30][80];
	int i,j,n=0,num=0;
	InitStack(&S);
	ch=getchar();
	while(ch!='!')
	{	while(ch!='!'&&ch!='\n')
		{	switch(ch)
			{	case '#': Pop(&S); break;
				case '@': InitStack(&S); break;
				default : Push(&S,ch);	}
			ch=getchar();	}
		while(!StackEmpty(&S))
			line[num][n++]=Pop(&S);
		line[num][n]='\0';
		num++;
		n=0;
		InitStack(&S);
		if (ch!='!') ch=getchar();	}
	printf("从终端输入的内容为:\n");
	for(j=0;j<num;j++)
	{	for(i=strlen(line[j])-1;i>=0;i--)
			printf("%c",line[j][i]);
		printf("\n");	}}
 main()
{
	
	LineEdit();
        getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -