C++数据结构路程:第四章,链式队列
来源:互联网 发布:linux nagios 安装 编辑:程序博客网 时间:2024/05/28 05:13
clear()函数有些问题,晚点调试,在看树,接下来才是数据结构的精华
#include "stdafx.h"
#include <iostream>
using namespace std;
class Node
{
private:
int data;
Node*pnext;
friend class lqueue;
public:
Node(int n);
~Node();
};
class lqueue
{
private:
Node*pfront;
Node*prear;
public:
lqueue();
~lqueue();
void clear();
bool isempty();
void insert(int vdata);
void dele();
void Show();
};
Node::Node(int n)
{
data=n;
pnext=0;
}
Node::~Node()
{
}
lqueue::lqueue()
{
pfront=0;
prear=0;
}
lqueue::~lqueue()
{
clear();
}
void lqueue::clear()
{
Node*pmove;
while(pfront)
{
pmove=pfront->pnext;
delete pfront;
pfront=pmove;
}
}
bool lqueue::isempty()
{
return pfront==0;
}
void lqueue::insert(int vdata)
{
if(pfront==0)
{
pfront=prear=new Node(vdata);
}
else
{
Node*pinsert=new Node(vdata);
pinsert->pnext=0;
prear->pnext=pinsert;
prear=pinsert;
}
}
void lqueue::dele()
{
if(isempty())
{
std::cout<<"there is no data"<<endl;
exit(1);
}
Node*pdele=pfront;
pfront=pfront->pnext;
delete pdele;
}
void lqueue::Show()
{
Node*pmove=pfront;
while(pmove)
{
cout<<" "<<pmove->data<<endl;
pmove=pmove->pnext;
}
}
int main(int argc, char* argv[])
{
lqueue queue;
int array[10]={1,3,5,7,9,0,2,4,6,8};
for(int i=0;i<10;i++)
{
queue.insert(array[i]);
}
queue.Show();
//queue.clear();
//queue.Show();
queue.dele();
queue.Show();
return 0;
}
- C++数据结构路程:第四章,链式队列
- 链式队列(数据结构C#)
- C++数据结构路程:第三章二阶段,链式栈
- [数据结构]第四章-队列
- 数据结构的C实现_链式队列
- 数据结构实现链式队列(C语言)
- 数据结构之---C语言实现链式队列
- 数据结构——链式队列(c++)
- c语言数据结构实现-链式队列
- 数据结构--用C实现链式队列
- 【数据结构-队列】链式队列
- C++——数据结构之 顺序队列 链式队列?
- 《大话数据结构》第四章 队列
- 【数据结构】链式队列 Linked_queue
- 数据结构之链式队列
- 基本数据结构:链式队列
- 基本数据结构:链式队列
- 数据结构之链式队列
- 各种内存条,PC,NB,SERVER内存条现货出售
- Git与SVN配合使用
- ALT系列快捷键
- .net 所有服务器脚本不能用的问题
- Drupal格式过滤安全设置与FCKEditor配置
- C++数据结构路程:第四章,链式队列
- mysql,sqlserver和oracle中查看当前库中所有表和字段信息
- [BCZ-HEAP]堆排序的实现,包括建堆,siftup(主要用于建堆)和siftdown(主要用于调整)函数的实现
- 缩小LVM分区大小
- Java编程规则(from thinking in java)
- Linux系统引导过程
- exceptions be caught by catch
- Oracle中USERENV和SYS_CONTEXT总结[转]
- MyEclipse 的快捷键大全