张信哲 发表于 2008-4-12 20:04

编译没错,但。。。。。。

//运行有错,帮看看吧。if你有空的话,谢谢哈。
#include<stdio.h>
#define Maxsize 30
typedef struct
{
        int s[Maxsize];
        int *top;
        int *base;
        char *c;
}stack;

void initstack(stack *st)  
{
        st->top=st->base;
}

int push(stack *st,int x)
{
       
        if(st->top-st->base>=Maxsize-1)
            return 0;
        else
        {
       
                *st->top++=x;   
                return 1;
        }
}

int stackempty(stack st)
{
        if(st.top==st.base)
                return 1;
        else
                return 0;
}

int pop(stack *st,int *x)
{
        if (st->base==st->top)
                return 0;
        else
        {
                *x=(*st->top)--;
                return 1;
        }
}

int stackTraverse(stack st,void(*vi)(int*))  
{
        int *p;
        int i;
        p=st.s;
        for(i=st.top;i>=st.base;i--)
                vi(p++);
        printf("\n");
        return 1;
}

int vi(int *c)  
{
        if(*c=='(')
                return 1;
        else
                return 0;
}

int main()
{
        char ch;
    stack st;
        scanf("%c",&ch);
        st.base=st.top=0;
        initstack(&st);
        if(ch=='(')
                push(&st,ch);
        else if(ch==')')
        {
                if(stackTraverse(st,vi))
                        pop(&st,ch);
        }
        else
                push(&st,ch);
        printf("that's all.");
}

张信哲 发表于 2008-4-12 20:33

帮下忙啊,在线等呢

页: [1]

编程论坛