C++ 作业 (循环链表构建队列)

/*
   author
   screen  name   Andromeda_Galaxy;
   chinese name   杨子俊
*/
#include<bits/stdc++.h>
using namespace std;
struct position
{
    int date=0;
    position *next;
    position *before;
};
struct  q_queue
{
    position p;  // front;
    position q;  // rear;
};
void build_queue(q_queue &ss)
{
    ss.q.next=&ss.p;
    ss.q.before=&ss.p;
    ss.p.next=&ss.q;
    ss.p.before=&ss.q;
}
void push_queue(q_queue &ss,int num)
{
    position *x1=ss.p.before;
    (*x1).next=new position;
    position *x2=(*x1).next;
    (*x2).before=x1;
    (*x2).next=&ss.p;
    ss.p.before=x2;
    (*x2).date=num;
}
void  top_queue(q_queue &ss)
{
    position *x1=ss.q.next;
    position  *x2=&ss.q;
    if( (*x1).next==x2)
        cout<<"error"<<endl;
    else
        cout<<(*x1).date<<endl;
}
void pop_queue(q_queue &ss)
{
    position *x1=ss.q.next;
    position *x2=(*x1).next;
    ss.q.next=x2;
    (*x2).before=&ss.q;
    delete(x1);
}
int32_t main()
{
    q_queue ss;
    build_queue(ss);
    push_queue(ss,1);
    push_queue(ss,2);
    push_queue(ss,3);
   // cout<<"-------"<<endl;
    top_queue(ss);
    pop_queue(ss);
    top_queue(ss);

}

 

转载于:https://www.cnblogs.com/Andromeda-Galaxy/p/9960094.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值