- 6
- 0
- 约9.61千字
- 约 14页
- 2018-06-06 发布于江西
- 举报
实验数据结构栈和队列的实现和应用.doc
实验1 栈和队列的?实现和应用?
实验目的
1.熟练掌握栈?、队列的建立?方法;
2.熟练掌握栈?和队列基本?操作;
3.栈和队列的?实例应用 。
实验内容
1.选用一种存?储结构建立?栈、队列
2.栈的应用:A desk calcu?latio?n(教科书P6?6)
3.队列验证:Menu-drive?n demon?strat?ion(教科书上P?93)
实验结果
总结算法应?用和结构优?缺点
栈:
#inclu?de iostr?eam
using? names?pace std;
const? int maxst?ack = 100;
enum Error?_code? {succe?ss = 1, overf?low = -1, under?flow = -1};
typed?ef int Stack?_entr?y;
class? Stack?
{
publi?c:
Stack?()
{
count? = 0;
}
bool empty?();
Error?_code? pop();
Error?_code? top(Stack?_entr?yitem);
Error?_code? push(const? Stack?_entr?y item);
int size();
priva?te:
int count?;
Stack?_entr?y entry?[maxst?ack];
};
Error?_code? Stack?::push(const? Stack?_entr?y item)
{
Error?_code? outco?me = succe?ss;
if(count? = maxst?ack) {
outco?me = overf?low;
}
else {
entry?[count?++] =item;
}
retur?n outco?me;
}
Error?_code? Stack?::pop()
{
Error?_code? outco?me = succe?ss;
if(count? == maxst?ack)
{
outco?me = under?flow;
}
else {
count?--;
}
retur?n outco?me;
}
Error?_code? Stack?::top(Stack?_entr?y item) {
Error?_code? outco?me = succe?ss;
if(count? == 0)
{
outco?me = under?flow;
}
else
{
item = entry?[count?-1];
}
retur?n outco?me;
}
bool Stack?::empty?()
{
bool outco?me = true;
if(count? 0)
{
outco?me = false?;
}
retur?n outco?me;
}
int Stack?::size()
{
retur?n count?;
}
int main()
{
Stack? numbe?rs;
for(int i = 0; i 10; i++)
{
numbe?rs.push(i);
}
int v;
while?(!numbe?rs.empty?())
{ numbe?rs.top(v);
coutvendl;
numbe?rs.pop();
}
retur?n 0;
}
队列:
#inclu?de iostr?eam
using? names?pace std;
const? int maxqu?eue = 100;
enum Error?_code? {succe?ss = 1, overf?low = -1, under?flow = -1};
typed?ef int Queue?_entr?y;
class? Queue? {
publi?c:
Queue?() {
count? = 0;
rear = maxqu?eu
您可能关注的文档
最近下载
- 《影视视听语言》第四版 07189 第六、七、八、九章.pptx VIP
- 声带息肉手术患者护理查房.pptx VIP
- 《影视视听语言》第四版 07189第五章.pptx VIP
- 《影视视听语言》第四版 07189第三章.pptx VIP
- 《影视视听语言》第四版 07189 第一章课件.pptx VIP
- 高一地理自然地理环境的差异性.pptx VIP
- 《影视视听语言》第四版 07189 第二章.pptx VIP
- 2026年南宁职业技术学院单招职业适应性考试模拟测试卷附答案解析.docx VIP
- 高中地理 人教版 选修一《自然环境的整体性与差异性》自然环境的整体性 课件.pptx VIP
- 健康证考试题及答案.docx VIP
原创力文档

文档评论(0)