数据结构-顺序队
#include<stdio.h> #define MaxSize 15 typedef struct SqQueue{ int data[MaxSize]; int front; int rear; }SqQueue,*SQueue; //初始化 void init(SqQueue &S){ S.front = 0; S.rear = S.front; } //判断队空 int isQueueEmpty(SqQueue S){ if(S.front == S.rear){ return 1; }else{ return 0; } } //进队操作 int enQueue(SqQueue &S,int x){ SqQueue ss; init(ss); if((S.rear+1)%MaxSize==S.front){ return 0; } S.rear = (S.rear + 1)%MaxSize; S.data[S.rear] = x; return 1; } //出队操作 int deQueue(SqQueue &S,int &x){ if(S.front == S.rear){ return 0; } S.front = (S.front + 1)%MaxSize; x = S.data[S.front]; return 1; } int main(){ SqQueue S; int a = enQueue(S,3); printf("%d",a); return 0; }