#include <iostream>
#include<string>
#include <vector>
using namespace std;
#define maxsize 100
//顺序栈的实现
typedef struct ListNode
{
int data;
ListNode* next;
}ListNode;
typedef struct ListQueue
{
ListNode* front;
ListNode* rear;
}ListQueue;
void push(ListQueue* s,int num)
{
ListNode* p=new ListNode;
if(!p)return;
p->data=num;
p->next=NULL;
s->rear->next=p;
s->rear=p;
}
int pop(ListQueue* s)
{
ListNode* p=s->front->next;
int num=p->data;
s->front->next=p->next;
if(s->rear==p)
s->rear=s->front;
delete p;
return num;
}
int main()
{
ListQueue* s=new ListQueue;
ListNode * p=new ListNode;
p->next=NULL;
s->front=p;
s->rear=p;
push(s,1);
push(s,2);
push(s,3);
cout<<pop(s)<<endl;
cout<<pop(s)<<endl;
cout<<pop(s)<<endl;
return 0;
}
队列的链表实现
最新推荐文章于 2024-04-09 14:24:07 发布