坚持可持续 2018-03-01 12:20 采纳率: 0%
浏览 1401
已采纳

预习数据结构用C语言写链队出现的一个小问题,可能关于指针

可以编译,但是没有办法运行
用vs调试,我猜测问题出现在指针初始化上面
(init 函数)

 #include<stdio.h> 
#include<malloc.h>

typedef struct  node
{  struct  node *next;
    int data;
} QNode;

//

typedef struct aaa
{  QNode *front;
   QNode *rear;   //指针指向 QNode 类型 
}LQueue;

// 初始化
void init (QNode *s,LQueue *L)
{   s= (struct  node* )malloc(  sizeof(struct  node));
    L= (LQueue* )malloc(  sizeof(LQueue));
     s->next=NULL;
     L->front=L->rear=(struct  node* )malloc(  sizeof(struct  node)) ;
     L->front=L->rear= s;


 } 
 //入队
 void push (LQueue *l,int x)
{   QNode *q=NULL;
   q= (struct  node* )malloc(  sizeof(struct  node));
     q->data=x;  q->next=NULL;           
   l->rear->next=q;
    l->rear = q;

 }  

 QNode *pop (QNode *p,LQueue *L,int *x)
 {   QNode *s=NULL; 
      s=L->front;
     L->front=L->front->next;
      *x = s->data;
      free(s);
 }

 //测试
 int main(void)
 {  int x=1;int *x1=NULL;
  QNode *a = NULL;
  LQueue *b =NULL;
  init (a,b);
  push( b ,x);
 // printf("%d",L->rear->data);

 }

  • 写回答

4条回答

  • trojanth 2018-03-02 01:52
    关注

    void init (QNode **s, LQueue **L)

    *s =malloc(....)
    *L = .......

    参数有问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 vhdl+MODELSIM
  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题