主题:[讨论]链队列的程序?大家看看哦!
链队列,大家帮忙改改啊!
#include "stdio.h"
struct linkqueue
{int data;
struct linkqueue *next;
};
struct queue
{
struct linkqueue front;
struct linkqueue rear;
};
void struct queue *enqueue(struct queue *q,int e)
{
struct linkqueue *p;
p=(struct linkqueue *)malloc(sizeof (struct linkqueue *));
p->data=e;
p->next=NULL;
(q->rear)->next=p;
q->rear=p;
}
void struct queue *dequeue(struct queue *q,int *e)
{
if(q->front==q->rear)
printf("error\n");
p=q->front->next;
e=p->data;
q->front->next=p->next;
if(q->rear==p)
q->rear=q->front;
free(p);
}
main()
{
struct queue *q;
struct linkqueue *p;
q->front=(struct queue *)maloc(sizeof(struct queue *));
q->rear=(struct queue *)malloc(sizeof(struct queue *));
q->front->next=NULL;
enqueue(q,3);
enqueue(q,4);
enqueue(q,2);
dequeue(q,3);
whilie(p)
{printf("%5d\n",p->data);
p=p->nxet;}
}
#include "stdio.h"
struct linkqueue
{int data;
struct linkqueue *next;
};
struct queue
{
struct linkqueue front;
struct linkqueue rear;
};
void struct queue *enqueue(struct queue *q,int e)
{
struct linkqueue *p;
p=(struct linkqueue *)malloc(sizeof (struct linkqueue *));
p->data=e;
p->next=NULL;
(q->rear)->next=p;
q->rear=p;
}
void struct queue *dequeue(struct queue *q,int *e)
{
if(q->front==q->rear)
printf("error\n");
p=q->front->next;
e=p->data;
q->front->next=p->next;
if(q->rear==p)
q->rear=q->front;
free(p);
}
main()
{
struct queue *q;
struct linkqueue *p;
q->front=(struct queue *)maloc(sizeof(struct queue *));
q->rear=(struct queue *)malloc(sizeof(struct queue *));
q->front->next=NULL;
enqueue(q,3);
enqueue(q,4);
enqueue(q,2);
dequeue(q,3);
whilie(p)
{printf("%5d\n",p->data);
p=p->nxet;}
}