#include<iostream>
#define elemType int
using namespace std ;
struct Que
{
Que* front;
Que* rear;
elemType data;
};
class lineQue
{
private:
Que* first;
int maxLength;
public:
lineQue();
~lineQue();
void addQ(elemType e);
void deleteQ(elemType &e);
};
lineQue::lineQue()
{
maxLength = 100 ;
first= new Que[maxLength] ;
first->front = first ;
first->rear = first ;
}
lineQue::~lineQue()
{
delete []first ;
}
void lineQue::addQ(elemType e)
{
first->rear->data = e ;
first->rear++ ;
}
void lineQue::deleteQ(elemType &e)
{
e=first->front->data;
first->front++ ;
}
int main()
{
lineQue lq;
int a = 0;
for(int i=0;i<10;i++)
{
lq.addQ(i) ;
}
for(int i=0;i<10;i++)
{
lq.deleteQ(a);
cout<<a<<" " ;
}
cout<<endl ;
system("pause");
}
#define elemType int
using namespace std ;
struct Que
{
Que* front;
Que* rear;
elemType data;
};
class lineQue
{
private:
Que* first;
int maxLength;
public:
lineQue();
~lineQue();
void addQ(elemType e);
void deleteQ(elemType &e);
};
lineQue::lineQue()
{
maxLength = 100 ;
first= new Que[maxLength] ;
first->front = first ;
first->rear = first ;
}
lineQue::~lineQue()
{
delete []first ;
}
void lineQue::addQ(elemType e)
{
first->rear->data = e ;
first->rear++ ;
}
void lineQue::deleteQ(elemType &e)
{
e=first->front->data;
first->front++ ;
}
int main()
{
lineQue lq;
int a = 0;
for(int i=0;i<10;i++)
{
lq.addQ(i) ;
}
for(int i=0;i<10;i++)
{
lq.deleteQ(a);
cout<<a<<" " ;
}
cout<<endl ;
system("pause");
}
本文介绍了一个简单的队列数据结构实现方法,通过C++代码展示了队列的基本操作,包括元素的添加(addQ)和删除(deleteQ)。该实现使用结构体来构建队列节点,并通过指针管理队列的头部和尾部。
5216

被折叠的 条评论
为什么被折叠?



