3.29
作者:互联网
1 #include<stdio.h> 2 typedef struct{ 3 int element[50]; 4 int front,rear; 5 int length; 6 int tag; 7 }SeqQueue; 8 void Create(SeqQueue*S) 9 { 10 int cnt,n; 11 scanf("%d",&n); 12 if(n)scanf("%d",&S->element[S->rear]); 13 for(cnt=0;cnt<n-1;cnt++) 14 { 15 S->rear=(S->rear+1)%(S->length); 16 scanf("%d",&S->element[S->rear]); 17 } 18 if(n<S->length&&n)S->tag=2; 19 else if(n==0)S->tag=0; 20 else S->tag=1;//2为非空,0为空,1为满 21 22 } 23 void In(SeqQueue*S,int e) 24 { 25 if(S->tag==1)return; 26 else { 27 S->rear=(S->rear+1)%(S->length); 28 S->element[S->rear]=e; 29 } 30 if((S->rear+1)%(S->length)==S->front)S->tag=1; 31 } 32 int Out(SeqQueue*S) 33 { 34 if(S->tag==0)return 0; 35 else{ 36 S->element[S->front]=0; 37 if(S->front==S->rear)S->tag=0; 38 else S->front=(S->front+1)%(S->length); 39 } 40 } 41 void Order(SeqQueue*S) 42 { 43 int i; 44 for(i=S->front;i!=S->rear;i=(i+1)%(S->length)) 45 printf("%d ",S->element[i]); 46 printf("%d ",S->element[i]); 47 } 48 int main() 49 { 50 SeqQueue S; 51 int e; 52 scanf("%d",&S.length); 53 S.front=0; 54 S.rear=0; 55 Create(&S); 56 scanf("%d",&e); 57 In(&S,e); 58 Order(&S); 59 printf("\n"); 60 Out(&S); 61 Order(&S); 62 return 0; 63 }
标签:int,element,front,length,tag,3.29,rear 来源: https://www.cnblogs.com/JT3895/p/15659655.html