資源簡介
包含內容:棧、隊列、循環隊列的數組實現方式和鏈表實現方式

代碼片段和文件信息
//雙端隊列
#include
#include
#define?Elemtype?int
#define?MaxSize?50
typedef?struct?Node{
Elemtype?queue[MaxSize];
int?top;
int?base;
}SqNode*SQueue;
//初始化隊列
void?InitQueue(SQueue?Q){
Q->top=Q->base=0;
}
//判空
int?IsEmptyQueue(SqNode?Q){
if(Q.top==Q.base) return?1;
return?0;
}
//底部出隊
int?EnbaseQueue(SQueue?QElemtype?*e){
//空?
if(IsEmptyQueue(*Q)) return?0;
*e=Q->queue[Q->base++];
Q->base=Q->base%MaxSize;
return?1;
}
//底部入隊
int?DebaseQueue(SQueue?QElemtype?e){
//滿?
if((Q->top+1)%MaxSize==Q->base)?return?0;
Q->base=(Q->base-1+MaxSize)%MaxSize;
Q->queue[Q->base]=e;
return?1;
}
//底部出隊
int?EnTopQueue(SQueue?QElemtype?*e){
//空?
if(IsEmptyQueue(*Q)) return?0;
*e=Q->queue[--Q->top];
return?1;
}
//頂部入隊
int?DeTopQueue(SQueue?QElemtype?e){
//滿?
if((Q->top+1)%MaxSize==Q->base)?return?0;
Q->queue[Q->top]=e;
Q->top=(Q->top+1)%MaxSize;
return?1;
}
int?main(){
SqNode?Q;
Elemtype?e;
InitQueue(&Q);
printf(“%d\n“IsEmptyQueue(Q));
DeTopQueue(&Q2);
DebaseQueue(&Q5);
EnbaseQueue(&Q&e);
printf(“%d\n“e);
EnbaseQueue(&Q&e);
printf(“%d\n“e);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4504??2018-08-05?10:09??CH03\CH03.dsp
?????文件????????533??2018-07-30?10:53??CH03\CH03.dsw
?????文件??????58368??2018-08-06?10:03??CH03\CH03.ncb
?????文件??????49664??2018-08-06?10:03??CH03\CH03.opt
?????文件???????1347??2018-08-06?09:55??CH03\CH03.plg
?????文件?????176194??2018-08-06?09:55??CH03\Debug\CH03.exe
?????文件?????193440??2018-08-06?09:55??CH03\Debug\CH03.ilk
????I.A....????215736??2018-08-06?09:46??CH03\Debug\CH03.pch
?????文件?????459776??2018-08-06?09:55??CH03\Debug\CH03.pdb
?????文件???????6120??2018-08-06?09:55??CH03\Debug\double.obj
?????文件???????3674??2018-08-06?09:46??CH03\Debug\Queue.obj
?????文件???????4031??2018-07-31?11:25??CH03\Debug\Queueli
?????文件???????4082??2018-07-30?16:10??CH03\Debug\stack.obj
?????文件???????4340??2018-08-05?10:09??CH03\Debug\stackli
?????文件??????41984??2018-08-06?09:55??CH03\Debug\vc60.idb
?????文件??????53248??2018-08-06?09:55??CH03\Debug\vc60.pdb
?????文件???????1204??2018-08-06?10:03??CH03\double.c
?????文件????????911??2018-08-06?09:46??CH03\Queue.c
?????文件???????1276??2018-07-31?11:25??CH03\Queueli
?????文件????????991??2018-07-30?15:43??CH03\stack.c
?????文件???????1118??2018-08-05?10:07??CH03\stackli
?????目錄??????????0??2018-08-06?09:46??CH03\Debug
?????目錄??????????0??2018-08-06?10:03??CH03
-----------?---------??----------?-----??----
??????????????1282541????????????????????23
- 上一篇:學生信息系統
- 下一篇:OpenGL實現的三維桌球游戲模擬源代碼
評論
共有 條評論