顺序队列的入队出队运算

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
41
42
43
44
45
46
47
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
typedef int datatype;
typedef struct node//顺序队列 定义 
{
    datatype data[MAXSIZE+1];
    datatype head,rear;
}sequeue;
sequeue *sq,SQ;
datatype x;
int SQ_ENSQUEUE(sequeue *sq,datatype x)//顺序队列的入队运算 
{
    if(sq->rear==MAXSIZE-1)
    {
        printf("队满");
        return 0;
     } 
     else
     {
         sq->rear++;
         sq->data[sq->rear]=x;
     }
}

int SQ_DEUEUE(sequeue *sq)//顺序队列的出队运算 
{
    if(sq->head==sq->rear)
    {
        printf("队空");
        return 0;
    }
    else 
    {
        sq->head++;
        return (sq->data[sq->head]);
    }
}
int main()
{    sq=&SQ;
    int SQ_ENSQUEUE(sequeue *sq,datatype x);
    int SQ_DEUEUE(sequeue *sq);
    scanf("%d",&x);
    SQ_ENSQUEUE(&SQ,x);
    printf("%d",SQ_DEUEUE(&SQ));
    return 0;
}