当前位置: 代码迷 >> C语言 >> 请教那出错
  详细解决方案

请教那出错

热度:247   发布时间:2008-03-13 11:05:58.0
请教那出错
#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define N 32000
typedef struct astack *stack;
typedef struct astack
{
    int top,maxtop;
    int*data;
}astack;

stack stacklnit (int size)
{
    stack s=(stack)malloc(sizeof*s);
    s->data=(int*)malloc(size*sizeof(int));
    s->maxtop=size-1;
    s->top=-1;
    return s;
}
void push(stack s,int x)
{
    if(s->top>=s->maxtop)printf("stack is full\n");
    else s->data[++s->top]=x;
        
}

int pop(stack s)
{
    if(s->top<0)printf("stack is empty\n");
    else return s->data[s->top--];
}
int main(int argc, char* argv[])
{
    char str1[20]={"push"},str2[20];
    int n,a,s,data,b,d[N];
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    printf("input the data of stack n=\n");
    scanf("%d",&n);
    b=0;
    while(scanf("%s,%d,%d",&str2,&s,&data)!=EOF);
    {
        while(s!=b)
        {
        stack ss=stacklnit(N);
        ss->top=d[s];
        if(strcmp(str1,str2)>=0)
        {
            push(ss,data);
        }
        else
        {
            if(ss->top<0)
                printf("%d",a=0);
            else
                printf("%d",a=pop(ss));
        }
        b=s;
        }
    }
    return 0;
}
搜索更多相关的解决方案: include  return  

----------------解决方案--------------------------------------------------------
你的栈有问题。。栈和树,链表都查不多。。要么你用递归要么你用循环。。改一下啊。。我路过。。
----------------解决方案--------------------------------------------------------
  相关解决方案