队列

来源:互联网 发布:python数据挖掘工具包 编辑:程序博客网 时间:2024/05/21 08:55
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){    int n;    scanf("%d",&n);    int m=n;    int ahead=0,atail=0;    int bhead=0,btail=0;    int aq_o[1001];    int bq_e[1001];    int tmp;    int cnt=0;    while(m--){        scanf("%d",&tmp);        if(tmp%2==0){            bq_e[btail++]=tmp;        }        else{            aq_o[atail++]=tmp;        }    }    atail--;    btail--;    while(1){        if(ahead<=atail){            if(cnt<n-1)                printf("%d ",aq_o[ahead++]);            else                printf("%d",aq_o[ahead++]);            cnt++;        }        if(ahead<=atail){            if(cnt<n-1)                printf("%d ",aq_o[ahead++]);            else                printf("%d",aq_o[ahead++]);            cnt++;        }        if(bhead<=btail){            if(cnt<n-1)                printf("%d ",bq_e[bhead++]);            else                printf("%d",bq_e[bhead++]);            cnt++;        }        if(cnt>n-1)            break;    }    return 0;}