weixin_51337768 2021-04-26 00:09 采纳率: 20%
浏览 27

大一队列模拟栈作业,求大神解答

下面是我写的代码,能运行但是你输入几个A就出来几个ERROR FULL

只有这个结果我也不知道为什么,求大神解答

 

 

 

#include <stdio.h>
#include <stdlib.h>
 
typedef struct Node
{
    int data;
    struct Node *next;
    int top;
}*Qnode;
 
 
Qnode CreateList()
{
    Qnode L;
    L=(Qnode)malloc(sizeof(struct Node));    
    L->next=NULL;
    L->top=0;
    return L; 
}
 
Qnode InsertList(Qnode L,int e,int n)
{
    if(L->top=n)
    {
        printf("ERROR FULL");
    }
    else
    {
        Qnode p;
        p=(Qnode)malloc(sizeof(struct Node));
        p->next=L->next;
        L->next=p;
        p->data=e;
        L->top++;
    }
    return     L;
}
 
Qnode PopList(Qnode L)
{
    if(L->top=0)
    {
        printf("ERROR EMPTY");
    }
    else
    {
        Qnode q;    
        q=(Qnode)malloc(sizeof(struct Node));    
        q=L->next;
        printf("%d\n",q->data);
        L->next=q->next;
        L->top--; 
    }
    return L;
}
 
int main()
{
    Qnode L; 
    L=CreateList();
    char m;
    int n,e;
    scanf("%d",&n);
    scanf("%c",&m);
    if(m=='T')
    {
        exit(0);
    }
    
    while(m!='T')
    {
        if(m=='A')
        {
            scanf("%d",&e);
            InsertList(L,e,n);
            
        }
        else if(m=='D')
        {
            PopList(L);
        }
        scanf("%c",&m);
    }
    return 0;
}

  • 写回答

2条回答 默认 最新

  • i__0o0__ 2021-04-26 10:20
    关注

     if(L->top=n),这是赋值表达式,,不是比较表达式

    而且,

    1. 这个是队列啊,为什么用insert,插入?

    2. 插入到初始节点后面,pop的时候还从初始节点后面取?这还是先入先出吗。。

    评论

报告相同问题?

悬赏问题

  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题