#include <STDIO.H> #include <STDLIB.H> #define MAX_DATA 10 typedef struct seqQueue { int data[MAX_DATA]; int front,rear; }seqqueue; void InitQueue(seqqueue *sq) { sq->front=0; sq->rear=0; } int Empty(seqqueue sq) { if(sq.front==sq.rear) return 1; else return 0; } int pushQueue(seqqueue *sq,int e) { if(sq->rear==(MAX_DATA-1)) return -1; sq->data[sq->rear]=e; sq->rear+=1; return 0; } int popQueue(seqqueue *sq,int *e) { if(sq->front==sq->rear) return -1; *e=sq->data[sq->front]; sq->front+=1; return 0; } int getHead(seqqueue sq,int *e) { *e=sq.data[sq.front]; return 0; } void main() { int i,j; int ar[]={12,23,32,45,56,65,78,87,92,100}; seqqueue sq; InitQueue(&sq); for(i=0;i<10;i++) { pushQueue(&sq,ar[i]); } while(Empty(sq)!=1) { popQueue(&sq,&j); printf("%d ",j); } printf("\n"); }
时间: 2024-11-15 06:13:27