数据结构作业,文章编辑(撤销,删除一行)
#include <stdio.h>
#include <stdlib.h>
typedef struct snode
{
char *data;
int top;
}snode;
int initstack(snode *S)
{
S->data=(char *)malloc(sizeof(char)*100);
S->top=0;
return 0;
}
int enstack(snode *S,char e)
{
S->data[S->top]=e;
S->top++;
return 1;
}
int destack(snode *S)
{
S->top--;
return 1;
}
void dispstack(snode *S)
{
int i;
for(i=0;i<S->top;i++)
{
printf("%c",S->data[i]);
}
}
void adjust(snode *S)
{
initstack(S);
char ch;
ch=getchar();
while(ch!=EOF)
{
while(ch!=EOF&&ch!='\n')
{
switch(ch)
{
case '#':destack(S);break;
case '@': S->top=0;break;
default: enstack(S,ch);break;
}
ch=getchar();
}
dispstack(S);
if(ch!=EOF) ch=getchar();
S->top=0;
}
}
int main()
{
snode S;
adjust(&S);
return 0;
}