-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinkqueue.c
More file actions
40 lines (40 loc) · 936 Bytes
/
Copy pathlinkqueue.c
File metadata and controls
40 lines (40 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct node
{ ElemType data;
struct node *next;
}qlink;
typedef struct
{ qlink *front;
qlink *rear;
}linkqueue;
void initqueue(linkqueue *LQ)
{
LQ->front=LQ->rear=(qlink *) malloc(sizeof(qlink));
if(!LQ->front) exit (0);
LQ->front->next=LQ->rear->next=NULL;
}
int emptyqueue (linkqueue LQ)
{
return(LQ.front->next==NULL&&LQ.rear->next==NULL);
}
void enqueue(linkqueue *LQ, ElemType x)
{ qlink *p;
p=(qlink * )malloc(sizeof(qlink));
p->data=x;
p->next=NULL;
LQ->rear->next=p;
LQ->rear=p;
}
int dequeue ( linkqueue *LQ, ElemType *e)
{ qlink *p;
if( emptyqueue(*LQ) ) return 0;
p=LQ->front->next;
*e=p->data;
LQ->front->next=p->next;
if( LQ->rear == p )
LQ->rear=LQ->front;
free(p);
return 1;
}