行编辑

作者在 2010-04-28 20:05:28 发布以下内容
#include<stdio.h>

#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10

#define OVERFLOW -2
#define  OK 1
#define  TURE 1
#define  Error 0

typedef struct
{  int *top;
    int *base;
    int stacksize;
}Sqstack;

void initstack(Sqstack *S)
{ S->base=(int)malloc(STACK_INIT_SIZE*sizeof (int));
    if(!S->base)exit(OVERFLOW);
    S->top=S->base;
    S->stacksize=STACK_INIT_SIZE;

}


int Clearstack(Sqstack *S)
{
    S->top=S->base;
    return S;
}


void Destorystack(Sqstack *S)
{
    free(S);
}

int StackEmpty(Sqstack *S)
{
    if(S->top==S->base)
    return Error;
}
void push(Sqstack *S,char e)
{
    if(S->top-S->base>=S->stacksize)
    {
      S->base=(int *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(int));
        if(!S->base)exit(OVERFLOW);
        S->top=S->base+S->stacksize;
        S->stacksize+=STACKINCREMENT;
    }
    *S->top++=e;

}
char Pop(Sqstack *S,char e)
{
    if(S->top==S->base)
        return Error;
    e=*--S->top;
  return e;
}

void Lineedit(Sqstack *S)
{
     Sqstack *SS;
    char ch ,e,n;
    initstack(SS);
     initstack(S);
    ch=getchar();
    while(ch!=' ')
    {
        while(ch!=' '&&ch!="\n")
        {
            switch(ch)
            {
                case '#':n=Pop(S,e);break;
                case '@':Clearstack(S);break;
                default :push(S,ch);break;
            }
            ch=getchar();
                        
        }
                while(StackEmpty(S)!=0)
                {
        *(SS->top)++=*--S->top;
                 }
               while(StackEmpty(SS)!=0)
                {  n=*--SS->top;
                    printf("%c",n);
          
                  }
        Clearstack(S);
        
            ch=getchar();
    }
    Destorystack(S);
}

int main()
{
    Sqstack *S,*SS;
    int e;
    printf("Enter the char:");
    Lineedit(S);
    return 0;
}
输入# 则#前面的一个字符删除  输入@ 则@前面的 一行字符串全部删除
默认分类 | 阅读 718 次
文章评论,共0条
游客请输入验证码
文章分类
最新评论