循环队列输出123

#include "stdio.h"
#define OK 1
#define ERROR  0
#define SIZE 10
typedef int status;
typedef int elemtype;           //元素为整型

typedef struct  {  //队列的顺序存储结构 
    elemtype *base;
    int front; 
    int rear;
}SqQueue;    

SqQueue Init_CirQueue(int n)//循环队列初始化 
{  
    SqQueue  Q ;
    int i;
    Q.base=new elemtype[SIZE];//分配存储空间  
    for(i=0 ;i<n;i++){
        Q.base [Q.rear]=i+1;
        Q.rear=(Q.rear+1)% SIZE ;
    }
     return(Q) ;
}

void output(SqQueue  Q)
{  
    int i;
    for(i=Q.front;i!=Q.rear;i=(i+1)%SIZE)
    printf("%d  ",Q.base[i]);
    printf("\n");
}

main()

    int i,e, n;
    SqQueue  Qa;
    Qa=Init_CirQueue(3);
    output(Qa);
}

posted @ 2021-11-18 20:23  一只狗狗  阅读(167)  评论(0)    收藏  举报