#include <stdio.h>
#include<stdlib.h>
/*此处是顺序队列数据结构定义*/
typedef int DataType;
struct seqQueue//请完成数据结构定义
{
int MAXNUM;
int front,rear;
DataType *element;
};
typedef struct seqQueue *PseqQueue;
//第一关
PseqQueue createNullQueue_seq(int m)
{//此处填写代码,创建一个空的顺序队列,能存放的最大元素个数为 m
//若m=0,则返回NULL
if(m==0)return 0;
PseqQueue q = (PseqQueue)malloc(sizeof(struct seqQueue));
if(q==NULL)return NULL;
q->MAXNUM = m;
q->front = 0;
q->rear = 0;
q->element = (int*)malloc(sizeof(int)*m);
return q;
}
//第二关
int isNullQueue_seq(PseqQueue Q)
{
//判断顺序(环形)队列是否为空,若为空,返回值为1,否则返回值为0,若队列不存在,则返回-1
if(Q==NULL)return -1;
else{
if(Q->rear==Q->front)return 1;
else return 0;
}
}
//第三关
int isFullQueue_seq(PseqQueue Q)
{
//判断环形队列是否已满,若已满,返回值为1,否则返回值为0
if((Q->rear+1)%Q->MAXNUM==Q->front)return 1;
else return 0;
}
//第四关
int enQueue_seq(PseqQueue Q ,DataType x)
{//在环形队列中插入数据元素x,若插入不成功,返回0;插入成功返回值为1
if(isFullQueue_seq(Q))return 0;
else{
Q->element[Q->rear] = x;
Q->rear++;
return 1;
}
}
//第五关
DataType delQueue_seq(PseqQueue Q)
{//出队并返回删除元素,若队列为空,则返回-1
if(isNullQueue_seq(Q))return -1;
else{
int temp = Q->element[Q->front];
Q->front++;
return temp;
}
}
//第六关
DataType front_seq(PseqQueue Q)
{// 取队首元素返回,若队列为空,则返回-1
if(isNullQueue_seq(Q))return -1;
else{
return Q->element[Q->front];
}
}
//销毁顺序队列,释放队列所占存储空间
int destroyQueue_seq(PseqQueue Q)
{
//返回值为销毁的栈中现有数据元素的个数,若待销毁的线性表不存在,则返回0
if(Q->element==NULL)return 0;
else return Q->rear-Q->front;
}
//第七关
void queueApp(int c[],int n)
{
//参数用于传递顾客编号和顾客人数,输出顾客接受服务后离开顺序
PseqQueue a = createNullQueue_seq(n+1);
PseqQueue b = createNullQueue_seq(n+1);
for(int i=0;i<n;i++){
if(c[i]%2==0){
enQueue_seq(b,c[i]);
}else{
enQueue_seq(a,c[i]);
}
}
int i = 0;
while(!isNullQueue_seq(a)&&!isNullQueue_seq(b)){
while(++i){
printf("%d ",delQueue_seq(a));
if(i%2==0)break;;
}
printf("%d ",delQueue_seq(b));
}
while(!isNullQueue_seq(a))printf("%d ",delQueue_seq(a));
while(!isNullQueue_seq(b))printf("%d ",delQueue_seq(b));
}
int main(void)
{
int m ,a[8];
scanf("%d",&m);
for(int i=0;i<m;i++)
scanf("%d",&a[i]);
queueApp(a,m);
}