国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

特殊環形隊列基本操作

2019-11-11 06:30:08
字體:
來源:轉載
供稿:網友
/*  問題:對于環形隊列如果知道隊頭指針和隊列中元素的個數。設計出這種  環形隊列的基本操作。  分析:        隊尾指針rear=(front+count)%MaxSize        隊空條件:count==0.        隊滿條件:count==MaxSize。*/#include <stdio.h>#include <stdlib.h>#define MaxSize 5typedef char ElemType;typedef struct{    ElemType data[MaxSize];//存放隊列中的元素    int front;//定義隊頭指針    int count;//定義元素個數}QuType;//定義順序隊的類型void InitQueue(QuType *&q)//初始化順序隊{    q = (QuType *)malloc(sizeof(QuType));    q->front= 0;    q->count = 0;}void DestroyQueue(QuType *&q)//銷毀順序隊{    free(q);}bool QueueEmpty(QuType *q)//判斷順序隊是否為空{    return (q->count==0);}bool enQueue(QuType *&q,ElemType e)//入隊{    int rear;    if(q->count==MaxSize)//隊滿上溢出        return false;    else    {        rear=(q->front+q->count)%MaxSize;//求隊尾位置        rear = (rear + 1)%MaxSize;        q->data[rear]=e;        q->count++;        return true;    }}bool deQueue(QuType *&q,ElemType &e)//出隊{    if(q->count==0)//對空下溢出        return false;    else    {        q->front = (q->front + 1)%MaxSize;        e = q->data[q->front];        q->count--;        return true ;    }}int main(){	ElemType e;	QuType *q;	PRintf("環形隊列基本運算如下:/n");	printf("  (1)初始化隊列q/n");	InitQueue(q);	printf("  (2)依次進隊列元素a,b,c/n");	if (!enQueue(q,'a')) printf("/t提示:隊滿,不能進隊/n");	if (!enQueue(q,'b')) printf("/t提示:隊滿,不能進隊/n");	if (!enQueue(q,'c')) printf("/t提示:隊滿,不能進隊/n");	printf("  (3)隊列為%s/n",(QueueEmpty(q)?"空":"非空"));	if (deQueue(q,e)==0)		printf("隊空,不能出隊/n");	else		printf("  (4)出隊一個元素%c/n",e);	printf("  (5)依次進隊列元素d,e,f/n");	if (!enQueue(q,'d')) printf("/t提示:隊滿,不能進隊/n");	if (!enQueue(q,'e')) printf("/t提示:隊滿,不能進隊/n");	if (!enQueue(q,'f')) printf("/t提示:隊滿,不能進隊/n");	printf("  (6)出隊列序列:");	while (!QueueEmpty(q))	{	deQueue(q,e);		printf("%c ",e);	}	printf("/n");	printf("  (7)釋放隊列/n");	DestroyQueue(q);    return 0;}

運行結果:


上一篇:POJ - 1987 樹分治

下一篇:JS之面向對象

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 樟树市| 横峰县| 闵行区| 都匀市| 阿拉善左旗| 开封县| 双流县| 香河县| 宁夏| 旺苍县| 葫芦岛市| 南充市| 丰原市| 图们市| 长顺县| 岳普湖县| 行唐县| 宁津县| 枣庄市| 泰来县| 松原市| 犍为县| 陵川县| 腾冲县| 沛县| 达州市| 定安县| 富阳市| 香河县| 商都县| 即墨市| 福州市| 漳平市| 沂水县| 望江县| 饶河县| 利辛县| 岫岩| 南城县| 云龙县| 潍坊市|