#include<iostream>
using namespace std;
typedef int ElemType;
typedef struct QueueNode node;
typedef struct QueueNode *link;
struct QueueNode{
ElemType data;
struct QueueNode *next;
};
link front=NULL;//队头
link rear=NULL;//队尾
void display(){
link point;
point=front;
while(point!=NULL){
cout<<point->data<<" ";
point=point->next;
}
cout<<endl;
}
/** 出队列
* @brief delQueue
* @return
*/
ElemType delQueue(){
link top;
ElemType temp;
if(front==NULL){
rear=NULL;
return -1;
}else{
top=front;
front=front->next;
temp=top->data;
free(top);
return temp;
}
}
/** 入队列
* @brief addQueue
* @param value
*/
void addQueue(ElemType value){
link new_node;
new_node=(link)malloc(sizeof(node));
new_node->data=value;
new_node->next=NULL;
if(front==NULL)
front=new_node;
else
rear->next=new_node;
rear=new_node;
}
数据结构之队列
最新推荐文章于 2022-05-17 20:25:55 发布