- 6
- 0
- 约1.69千字
- 约 4页
- 2017-03-08 发布于重庆
- 举报
循环队列(链表实现)
/*该程序在vs2010旗舰版下 成功编译运行正常*/
/*循环队列 链表实现 , 自行建立头文件 头文件实现 main引用 三个文件*/
//头文件
#ifndef _CIRCLE_QUEUE_H_
#define _CIRCLE_QUEUE_H_
template
struct Node T Data;
Node *Next;
;
template
class Circle_Queue public:
Circle_Queue ;
void Push_Queue T a ;
T POP_Queue ;
void Print_All ;
~Circle_Queue ;
private:
Node *End;
;
#endif
//头文件实现
#include
#includecircle_queue.h
template
Circle_Queue ::Circle_Queue End new Node ;
End- Next End; template
void Circle_Queue ::Push_Queue T a //入队操作 Node *p;
p new Node ;
p- Data a;
p- Next End- Next;
End- Next p;
End p; template
T Circle_Queue ::POP_Queue if End End- Next //判断队列是否为空 throw QUEUE IS NULL! ; Node *p,*Head; T temp; Head End- Next; p Head- Next;
if p End //如果已经到达队尾,则对该队列进行置空队,并返回最后一个值 temp End- Data;
End- Next End;
delete Head; else temp p- Data;
Head- Next p- Next; delete p; return temp; template
void Circle_Queue ::Print_All //显示所有队列元素 if End End- Next throw QUEUE IS NULL! ; Node *Head;
Head End- Next- Next; //第一个 节点不是有效节点
while Head ! End- Next cout Head- Data ;
Head Head- Next; template
Circle_Queue ::~Circle_Queue if End ! End- Next Node *p1,*p2; p1 End- Next; p2 p1; while p1 ! End p1 p1- Next; delete p2; p2 p1; delete End; //main引用
#include
#includecircle_queue.cpp
using namespace std;
int main int m,n,b,d 0;
try Circle_Queue c1;
c1.Push_Queue 1 ;
c1.Push_Queue 2 ; c1.Push_Queue 3 ;
c1.Print_All ;
m c1.POP_Queue ; n c1.POP_Queue ;
b c1.POP_Queue ;
d c1.POP_Queue ; catch const char *str cout str endl; cout m n b d endl; system pause ;
return 0;
您可能关注的文档
- 徐州师范大学游泳协会章程.doc
- 徐州建筑之管中窥豹篇.doc
- 徐州市采煤塌陷地农业综合开发.doc
- 徐州悄然兴起膏方热.doc
- 徐州段监理质量周报(2012119-15).doc
- 徐州民俗博物馆春节期间开放好评如潮.doc
- 徐州房地产公司汇总.docx
- 徐州汉光闸间隙保护.doc
- 徐州活性炭吸附性.doc
- 徐州特色小吃介绍.doc
- 小区绿化施工协议书.docx
- 墙面施工协议书.docx
- 1 古诗二首(课件)--2025-2026学年统编版语文二年级下册.pptx
- (2026春新版)部编版八年级道德与法治下册《3.1《公民基本权利》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《4.3《依法履行义务》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.2《按劳分配为主体、多种分配方式并存》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.1《公有制为主体、多种所有制经济共同发展》PPT课件.pptx
- 初三教学管理交流发言稿.docx
- 小学生课外阅读总结.docx
- 餐饮门店夜经济运营的社会责任报告(夜间贡献)撰写流程试题库及答案.doc
原创力文档

文档评论(0)