主函数部分的错误不会改,求帮忙
题目如下
编写一个程序,任意输入n个100以内的数,将它们的奇数和偶数分别存入链队为Q1和Q2中,然后配对输出链队Q1、Q2中的值,直到任一队列为空为止。
#include<stdio.h>
#include<stdlib.h>
# define OK 1
# define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int QElemType;
typedef struct QNode{
QElemType data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct{
QueuePtr front;
QueuePtr rear;
}LinkQueue;
Status InitQueue(LinkQueue &Q){
//构造新的队列
Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));
if(!Q.front) exit(OVERFLOW);
Q.front->next=NULL;
return OK;
}
Status EnQueue(LinkQueue &Q, QElemType e){
//插入元素e为Q的新的队尾元素
QueuePtr p;
p=(QueuePtr)malloc(sizeof(QNode));
if(!p) exit(OVERFLOW);
p->next=NULL;
p->data=e;
Q.rear->next=p;
Q.rear=p;
return OK;
}
Status DeQueue(LinkQueue &Q,QElemType &e){
//若队不空,删除Q的队头元素,并用e返回其值
QueuePtr p;
if(Q.front==Q.rear) return ERROR;
p=(QueuePtr)malloc(sizeof(QNode));
if(!p) exit(OVERFLOW);
p=Q.front->next;
e=p->data;
Q.front->next=p->next;
if(Q.rear==p) Q.rear=Q.front;
free(p);
return OK;
}
int main(){
struct Q1,Q2;
InitQueue(&Q1);
InitQueue(&Q2);
int cou,cou1,cou2;
scanf("%d",&cou);
int a,i,j;
for(i=0;i<cou;i++){
scanf("%d",&a[i]);
if(a[i]%2==0){
EnQueue(&Q1,a[i]);
cou1++;}
else{
EnQueue(&Q2,a[i]);
cou2++;
}
}
int min,n1,n2;
min=(cou1<=cou2)?cou1:cou2;
for(j=0;j<min;j++){
DeQueue(&Q1,&n1);
DeQueue(&Q1,&n2);
printf("%d %d\n",n1,n2);
}
return 0;
}