队列的入队问题
程序代码:
#include <stdio.h> #include<stdlib.h> typedef struct duilie { int a; struct duilie *next; }s,*s1; //struct duilie *front,*rear; struct zhixiang { s1 front; s1 rear; }*q; int jianli(); int rudui(struct zhixiang *q,int e); int main() { int a,i,c; printf("\n"); printf(" 主菜单 \n"); printf(" 1 建立链表队列 \n"); printf(" 2 入队一个元素 \n"); printf(" 3 出队一个元素 \n"); printf(" 4 结束程序运行 \n"); printf("请输入你的选择:"); scanf("%d",&a); switch(a) { case 1:jianli();break; case 2:{ printf("请输入你要入队的元素:"); scanf("%d",&c); rudui(q,c); }break; } return 0; } int jianli() { q->front = (s1)malloc(sizeof(s)); if(q->front==NULL) return 0; q->rear=q->front; q->front->next=NULL; //front->a=1; //printf("\n%d",front->a); return 1; } int rudui(struct zhixiang *q,int e) { struct duilie *d; d = (s1) malloc (sizeof(s)); if(d==NULL) return 0; d->a=e; d->next=NULL; q->rear->next=d;printf("%d",e);getchar();getchar(); q->rear=d; printf("%d",q->rear->a); return 1; }
在入队的时候
q->rear->next=d;
这一行代码出错了。。。求大神教我...