#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef bool status;
typedef int elmetype;
typedef struct node
{
elmetype date;
struct node *next,*front;
}Queue;
status creat_queue(Queue *&L)
{
L=(Queue*)malloc(sizeof(Queue));
if(!L) return false;
L->next=L->front=L;
return true;
}
status judge_empty(Queue *L)
{
return (L->next==L);
}
status push_elme(Queue *&L,elmetype x)
{
Queue *p=(Queue *)malloc(sizeof(Queue));
if(!p) return false;
p->date=x;
p->next=L;
p->front=L->front;
L->front->next=p;
L->front=p;
//printf("push%d\n",L->front->date);
return true;
}
status pop_elme(Queue *&L)
{
if(L->next==L) return 0;
Queue *temp=L->next;
//printf("pop%d\n",temp->date);
L->next=temp->next;
temp->next->front=L;
free(temp);
return true;
}
int main()
{
Queue *L;
creat_queue(L);
for(int i=1;i<=10;i++)
{
push_elme(L,i);
}
for(int i=1;i<=10;i++)
{
pop_elme(L);
}
return 0;
}
基于双向循环链表实现的队列
最新推荐文章于 2024-07-31 22:05:27 发布