数据结构-链式队列
//数据结构
typedef struct LNode{
int data;
struct LNode*next;
}LNode;
typedef struct{
LNode *front,*rear;
}queue;
//初始化:建立头结点
q.front = q.rear = (LNode*)malloc(sizeof(LNode));
q.front->next = NULL;
//插入
bool push(int x)
{
//无需判满
LNode *e = (Lnode*)malloc(sizeof(LNode));
e->data = x;
e->next = NULL;
q.rear->next = e;//插入链尾
q.rear = e; //修改尾指针
return true;
}
//删除
bool pop(int &x)
{
//判空
if(q.front == q.rear)return false;
LNode* p = q.front->next;
x = p->data;
q.front->next = p.next;
//判断删除后是否为空
if(q.rear = p)
q.rear = q.front;
free(p);
return true;
}