c语言实现队列
作者:互联网
#include <stdio.h> #include <stdlib.h> #define MAXQSIZE 100 typedef int QELemType; typedef struct { QELemType *base; int front; //头 int rear; //尾 int count; }SqQueue; void InitSqQueue(SqQueue &S){ S.front = S.rear = 0; S.count = 0; S.base = (QELemType *)malloc(MAXQSIZE * sizeof(QELemType)); printf("SqQueue init success \n"); } void InsertSqQueue(SqQueue &S,QELemType e){ S.base[S.rear] = e; S.rear ++; S.count ++; } void Pop(SqQueue &S){ QELemType q; q = S.base[S.front]; S.front ++; S.count --; } void GetELem(SqQueue S){ int i = S.front; while(i < S.rear){ printf("data is %d\n",S.base[i]); i ++; } } int main(){ SqQueue S; InitSqQueue(S); for (int i=0;i<10;i++){ InsertSqQueue(S, i+1); } Pop(S); GetELem(S); }
标签:语言,QELemType,队列,SqQueue,实现,int,base,front,rear 来源: https://www.cnblogs.com/Pynu/p/16327782.html