- Create_LQueue(int size) 创建大小为size的链队列
- Push_LQueue(datatype x)
queue.push()
操作数入队
- Pop_LQueue()
queue.pop()
队列尾部出队
#include<bits/stdc++.h>
using namespace std;
typedef int datatype;
class Node{
public:
datatype data;
Node *next;
};
class LQueue{
public:
LQueue();
~LQueue();
void Create_LQueue(int size);
void Push_LQueue(datatype x);
datatype Pop_LQueue();
int size;
Node *head;
};
LQueue::LQueue(){
head=new Node;
this->head->next=NULL;
this->head->data=0;
}
LQueue::~LQueue(){
delete head;
}
void LQueue::Create_LQueue(int size){
Node *pnew;
Node *ptemp;
this->size=size;
ptemp=this->head;
for(int i=0;i<size;++i){
pnew =new Node;
cin>>pnew->data;
ptemp->next=pnew;
ptemp=pnew;
}
}
void LQueue::Push_LQueue(datatype x){
Node *ptemp;
ptemp=new Node;
ptemp->data=x;
this->head->next=ptemp;
}
datatype LQueue::Pop_LQueue(){
Node *ptemp;
ptemp=this->head->next;
while(ptemp->next!=NULL){
ptemp=ptemp->next;
}
datatype x=ptemp->data;
free(ptemp);
return x;
}