毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

数据结构课程设计-文本编辑器

更新时间:2007-10-20:  来源:毕业论文
数据结构课程设计-文本编辑器|数据结构课程设计

#include "stdio.h"
#include "stdlib.h"
#define OK 1
#define ERROR 0
#define OVERFLOW -1
//#define EOF -1
#define STACK_INIT_SIZE 10
#define STACKINCREMENT 1000
#define MAXQSIZE 10

static int i=0;
typedef char ElemType;
typedef struct StackNode//构造栈
{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;

ElemType InitStack(SqStack *S)//初始化栈
{
S->base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType));
if(!S->base)
{
exit(OVERFLOW);
}
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
}

ElemType StackEmpty(SqStack *S)//判断栈是否为空
{
if(S->top==S->base)
return OK;
else
return ERROR;
}

ElemType Push(SqStack *S,ElemType e)//进栈操作
{
if(S->top-S->base>=S->stacksize)
{
S->base = (ElemType *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(ElemType));
if(!S->base)
{
exit(OVERFLOW);
}
S->top = S->base+S->stacksize;
S->stacksize+=STACKINCREMENT;
}
*S->top++=e;
return OK;
}

ElemType Pop(SqStack *S,ElemType *e)//出栈操作
{


if(S->top==S->base)
{
return ERROR;
}
*e=*--S->top;
//printf("%d\n",e);
// return e;
return 0;
}

void ClearStack(SqStack *S)//清空栈
{
S->top=S->base;
}

ElemType LineEdit(SqStack *S )//文本编译
{
char ch, e, a[30];
int i ;
ch = getchar();


while(1)
{
while (ch!='\n')
{
switch(ch)
{
case '#':
Pop(S,&e);
break;
case
'@':
ClearStack(S);
break;
default:
Push(S,ch);
break;
}
ch = getchar();
}
i = 0;
while (!StackEmpty(S))
{
Pop(S,&e);
a[i++]=e;
}
for(--i; i>= 0; i--)
{
printf("%c",a[i]);
}
printf("\n");
ClearStack(S);
ch = getchar();
}

return 0;
}

int main(void)
{

SqStack S;

InitStack(&S);
LineEdit(&S);

system("pause");
return 0;
}

数据结构课程设计-文本编辑器下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。