注册 登录
编程论坛 C++教室

求教/(ㄒoㄒ)/~为什么总是提醒我error C2146: syntax error : missing ';' before identifier 'Pop

fanyueqi 发布于 2015-05-08 21:31, 976 次点击
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define NULL 0

typedef int status;
typedef int Elemtype;

typedef struct node
{
    Elemtype data;
    struct node *next;
} LinkStack;

Status PopLinkStack(LinkStack *top,Elemtype &e)
{
    LinkStack *p;
    if(EmptyLinkStack(top))
    {
        printf("Stack Underflow");
        return OVERFLOW;
    }
    else
    {
        y=top->data;
        p=top;
        top=top->next;
        free(p);
        return OK;
    }
}

LinkStack * InitLinkStack(LinkStack *top)
{
    top=NULL;
    return top;
}


int EmptyLinkStack(LinkStack *top)
{
    if(top==NULL)
        return TRUE;
    else
        return FALSE;
}


LinkStack * PushLinkStack(LinkStack *top,Elemtype e)
{
    LinkStack *p;
    p=(LinkStack *)malloc(sizeof(LinkStack));
    p->data=e;
    p->next=top;
    top=p;
    return top;
}



Status GetTop(LinkStack *top,Elemtype &e)
{
    if(EmptyLinkStack(top))
    {
        printf("Stack Underflow");
        return OVERFLOW;
    }
    else
    {
        y=top->data;
        return OK;
    }
}

int main()
{
    int quit=1,k;
    Elemtype e;
    LinkStack *top=NULL;
    InitLinkStack(top);
    printf("1.压栈\n2.弹栈\n3.判断栈空\n4.取栈顶元素\n5.退出\n");
    scanf("%d",&k);
    while(1)
    {
        switch(k)
        {
        case 1:
        {
                printf("请输入压栈的数字:");
                scanf("%d",&e);
                PushLinkStack(top,e);
                break;
        }
        case 2:
        {
                if(PopLinkStack(S)==1)
                    printf("弹栈数据%d",e);
                else
                    printf("弹栈失败");
                break;
        }
        case 3:
        {
                if(EmptyLinkStack(S))
                    printf("空栈");
                else
                    printf("栈非空");
                break;
        }
        case 4:
        {
                if(GetTop(top,e)==1)
                    printf("栈顶元素%d",e);
                else
                    printf("栈空");
                 break;
        }
        case 5:
        {
                return 1;
        }
    }
}
2 回复
#2
yangfrancis2015-05-09 07:08
为什么scanf("%d",&k);不是写在循环体内?怎么去执行不同的case?
#3
小狼烟2015-05-11 11:41
你的大括号少了一个!!,在主函数的最后面添加一个大括号就好了
1