加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

顺序结构循环队列的基本操作(一)(进队,出队)待优化

发布时间:2020-12-14 05:09:58 所属栏目:大数据 来源:网络整理
导读:#includestdio.h#define ElemType int#includemalloc.h#define MAXSIZE 10typedef struct{ ElemType *data; int front,rear;}Queue;typedef struct BitNode{ ElemType data; struct Bitree *Lchild,*Rchild;}BitNode;Queue Init_queue(Queue Q){ Q.data=(Ele

#include<stdio.h>#define ElemType int#include<malloc.h>#define MAXSIZE 10typedef struct{ ElemType *data; int front,rear;}Queue;typedef struct BitNode{ ElemType data; struct Bitree *Lchild,*Rchild;}BitNode;Queue Init_queue(Queue Q){ Q.data=(ElemType *)malloc(MAXSIZE*sizeof(ElemType)); Q.front=Q.rear=0; return Q;} Queue Enter_queue(Queue Q,ElemType e){ if((Q.rear+1)%MAXSIZE==Q.front){ printf("队满"); }else{ *(Q.data+Q.rear)=e; Q.rear=(Q.rear+1)%MAXSIZE; } return Q;}Queue Leave_queue(Queue Q){ ElemType e; if(Q.rear==Q.front){ printf("队空"); }else{ printf("eo"); e=*(Q.data+Q.front); printf("%d出队n",e); Q.front=(Q.front+1)%MAXSIZE; } return Q;}int main(){ Queue Q; int e,a; Q=Init_queue(Q); printf("请输入入队的数:n"); scanf("%d",&e); while(e!=-1){ Q=Enter_queue(Q,e); scanf("%d",&e); } while(*(Q.data+Q.front)){ Q=Leave_queue(Q); } return 0; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读