qq_39226270 2017-06-20 07:42 采纳率: 100%
浏览 897
已采纳

堆栈顺序栈的运用。能不能在我给的基础上修改

/*设计一个简单的文字编辑器,使其具有删除打错字符的功能*/
/*约定:@表示删除前面一个字符,#表示删除前面所有字符,$表示编辑结束*/
#include
#define maxsize 64
typedef struct
{
void* data[maxsize];
int top;
}seqstack;

void SETNULL(seqstack *s){

s->top=-1;printf("cei1\n");printf("%d",s->top);

}

int EMPTY(seqstack *s){
printf("cei10\n");

if(s->top>=0)
    return 0;
else
    return 1;

}

char POP(seqstack *s)
{ printf("cei2\n");

if(EMPTY(s))
{
    printf("underflow");
    return NULL;}
else
{
    s->top--;
    return(s->data[s->top+1]);
}

}

seqstack *PUSH(seqstack *s,char x){
printf("cei3\n");

int i;
if(s->top==maxsize-1)
{
    printf("overflow");
    return NULL;
}
else
{

 s->top++;
  s->data[s->top]=x;
}
return s;

}

void shuchu(seqstack *s){
printf("cei4\n");

int i=-1;
printf("字符为\n");
while(i!=s->top){
    printf("%s\t",s->data[i+1]);
    i++;
}

}

void EDIT(seqstack *s)
{
char c;

SETNULL(&s);    printf("cei5\n");

c=getchar();

while(c!='$')
{

    if(c=='@') {
        POP(&s);    printf("cei6\n");

    }
    else if(c=='#') {
            SETNULL(&s);    printf("cei7\n");

    }
    else {printf("1%d",s->top);
            PUSH(&s,c);    printf("cei8\n");

    }
    getchar();
    shuchu(&s);    printf("cei9\n");

    c=getchar();

}

}

void main()
{

seqstack *s;
EDIT(s);

}

  • 写回答

3条回答 默认 最新

  • s_listening 2017-06-20 08:25
    关注

    改动可以实现功能:
    你打log的代码没有删掉

    /*设计一个简单的文字编辑器,使其具有删除打错字符的功能*/
    /*约定:@表示删除前面一个字符,#表示删除前面所有字符,$表示编辑结束*/
    #include <stdio.h>
    
    #define maxsize 64
    typedef struct
    {
        char data[maxsize];
        int top;
    }seqstack;
    void SETNULL(seqstack *s) {
        s->top = -1; printf("cei1\n"); printf("%d", s->top);
    }
    int EMPTY(seqstack *s) {
        printf("cei10\n");
        if (s->top >= 0)
            return 0;
        else
            return 1;
    }
    char POP(seqstack *s)
    {
        printf("cei2\n");
        if (EMPTY(s))
        {
            printf("underflow");
            return NULL;
        }
        else
        {
            return s->data[s->top--];
        }
    }
    seqstack *PUSH(seqstack *s, char x) {
        printf("cei3\n");
        int i;
        if (s->top == maxsize - 1)
        {
            printf("overflow");
            return NULL;
        }
        else
        {
    
            s->top++;
            s->data[s->top] = x;
        }
        return s;
    }
    void shuchu(seqstack *s) {
        printf("cei4\n");
        int i = -1;
        printf("字符为\n");
        while (i != s->top) {
            printf("%c", s->data[i + 1]);
            i++;
        }
        printf("\n");
    }
    void EDIT(seqstack *s)
    {
        char c;
        SETNULL(s);    printf("cei5\n");
    
        c = getchar();
    
        while (c != '$')
        {
    
            if (c == '@') {
                POP(s);    printf("cei6\n");
    
            }
            else if (c == '#') {
                SETNULL(s);    printf("cei7\n");
    
            }
            else {
                printf("1%d\n", s->top);
                PUSH(s, c);    printf("cei8\n");
    
            }
            getchar();
            shuchu(s);    printf("cei9\n");
    
            c = getchar();
    
        }
    }
    void main()
    {
        seqstack *s = new seqstack;
        EDIT(s);
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器