队列
// 队列的各种实现
#include <cstdio>
#include <cstdlib>
//#define _OJ_
typedef struct Lnode
{
int data;
struct Lnode *next;
} qNode, *Queueptr;
typedef struct
{
Queueptr front;
Queueptr rear;
}queue, *Linkqueue;
void
creat_queue(Linkqueue q)
{
q->front = q->rear = (Queueptr) malloc (sizeof(qNode));
q->front->next = NULL;
}
int
isempty(Linkqueue q)
{
if(q->front == q->rear)
return 1;
else
return 0;
}
void
Enqueue(Linkqueue q)
{
printf("%p\n", q->rear);
Queueptr p1;
p1 = (Queueptr) malloc (sizeof(qNode));
scanf("%d", &p1->data);
printf("%d\n", p1->data);
p1->next = NULL;
q->rear->next = p1;
q->rear = p1;
printf("%p\n", q->rear);
}
int
Dequeue(Linkqueue q)
{
int e;
Queueptr p;
p = q->front->next;
e = p->data;
q->front->next = p->next;
if(q->rear == p) q->rear = q->front;
free(p);
return e;
}
int main(int argc, char const *argv[]) {
#ifndef _OJ_ //ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
Linkqueue q;
creat_queue(q);
printf("%d\n",isempty(q));
int i, n, x;
scanf("%d", &n);
while (n--)
Enqueue(q);
while (q->rear != q->front)
printf("%d\n", Dequeue(q));
return 0;
}