《C++捷径教程》读书笔记--Chapter 11--类(第三部分)
2006-03-12 21:08
441 查看
//--《C++捷径教程》读书笔记--Chapter 11--类(第三部分)
//--Chapter 11--类
//--03/12/2006 Sun.
//--Computer Lab
//--Liwei
//--程序#3 queuq
#include <iostream>
using namespace std;
class queue{
int sloc,rloc;
int q[100];
public:
queue();
~queue();
void qput(int i);
int qget();
};
queue::queue()
{
rloc=sloc=0; q[0]=0;
cout<<"Queue initialized./n";
}
queue::~queue()
{
cout<<"Queue destroyed./n";
}
void queue::qput(int i)
{ if(sloc==100)
{cout<<"Queue is full./n"; return;}
sloc++;
q[sloc]=i;
}
int queue::qget()
{
if(rloc==sloc)
{cout<<"Queue underflow./n"; return 0;}
rloc++;
return q[rloc];
}
int main()
{
queue a,b;
a.qput(10);
b.qput(19);
a.qput(20);
b.qput(1);
cout<<a.qget()<<" ";
cout<<a.qget()<<" ";
cout<<b.qget()<<" ";
cout<<b.qget()<<"/n";
return 0;
}
//--Chapter 11--类
//--03/12/2006 Sun.
//--Computer Lab
//--Liwei
//--程序#3 queuq
#include <iostream>
using namespace std;
class queue{
int sloc,rloc;
int q[100];
public:
queue();
~queue();
void qput(int i);
int qget();
};
queue::queue()
{
rloc=sloc=0; q[0]=0;
cout<<"Queue initialized./n";
}
queue::~queue()
{
cout<<"Queue destroyed./n";
}
void queue::qput(int i)
{ if(sloc==100)
{cout<<"Queue is full./n"; return;}
sloc++;
q[sloc]=i;
}
int queue::qget()
{
if(rloc==sloc)
{cout<<"Queue underflow./n"; return 0;}
rloc++;
return q[rloc];
}
int main()
{
queue a,b;
a.qput(10);
b.qput(19);
a.qput(20);
b.qput(1);
cout<<a.qget()<<" ";
cout<<a.qget()<<" ";
cout<<b.qget()<<" ";
cout<<b.qget()<<"/n";
return 0;
}
相关文章推荐
- 《C++捷径教程》读书笔记--Chapter 11--类(第四部分)
- 《C++捷径教程》读书笔记--Chapter 11--类(第五部分)
- 《C++捷径教程》读书笔记--Chapter 11--类(第六部分)
- 《C++捷径教程》读书笔记--Chapter 11--类(第二部分)
- 《C++捷径教程》读书笔记--Chapter 18--C++的I/O系统--7-11
- 《C++捷径教程》读书笔记--Chapter 6--指针(第二部分)
- 《C++捷径教程》读书笔记--Chapter 8--函数,第二部分:引用,重载和默认参数
- 《C++捷径教程》读书笔记--Chapter 9--更多的数据类型与运算符(第二部分)
- 《C++捷径教程》读书笔记--Chapter 7--函数,第一部分:基础知识(第一部分)
- 《C++捷径教程》读书笔记--Chapter 7--函数,第一部分:基础知识(第二部分)
- 《C++捷径教程》读书笔记--Chapter 11--类(第一部分)
- 《C++捷径教程》读书笔记--Chapter 4--程序控制语句(第二部分)
- 《C++捷径教程》读书笔记--Chapter 5--数组和字符串(第二部分)
- 《C++捷径教程》读书笔记--Chapter 11--类(完结)
- 《C++捷径教程》读书笔记--Chapter 18--C++的I/O系统--4-6
- 《C++捷径教程》读书笔记--Chapter 18--C++的I/O系统--12-15
- 《C++捷径教程》读书笔记--Chapter 6--指针(第一部分)
- <2012 11 15> Linux内核驱动总体框架——《深入理解Linux内核》chapter 13 读书笔记
- 《C++捷径教程》读书笔记--Chapter 16--模板(完结)
- HTML5权威指南读书笔记【第三部分】