#include <iostream>
using namespace std;

typedef struct QNode
{
	int data;
	struct QNode * next;
}QNode,*QueuePtr;

typedef struct
{
	QueuePtr front;
	QueuePtr rear;
}LinkQueue;


bool init(LinkQueue & L)
{
	L.front = L.rear = (QueuePtr)malloc(sizeof(QNode));
	if (!L.front) return false;
	L.front->next = NULL;
	return true;
}

bool destroy(LinkQueue & L)
{
	while (L.front)
	{
		L.rear = L.front->next;
		free(L.front);
		L.front = L.rear;
	}
	return true;
}



bool EnQueue(LinkQueue & L, int item)
{
	QueuePtr p = (QNode *)malloc(sizeof(QNode));
	if (!p) return false;
	p->data = item;
	p->next = NULL;
	L.rear->next = p;
	L.rear = p;
	return true;
}


bool DeQueue(LinkQueue & L, int & item)
{
	if (L.rear == L.front) return false;
	QueuePtr p = L.front->next;
	item = p->data;
	if (p = L.rear)
	{
		L.rear = L.front;
	}
	L.front->next = L.front->next->next;
	free(p);
	return true;

}

  

posted on 2018-10-04 09:52  一起_007  阅读(48)  评论(0编辑  收藏  举报