队列顺序存储结构C++实现

本文介绍了一个简单的队列数据结构实现方法,通过C++代码展示了队列的基本操作,包括元素的添加(addQ)和删除(deleteQ)。该实现使用结构体来构建队列节点,并通过指针管理队列的头部和尾部。
#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");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值