c 언어 체인 팀 의 실현

#include
typedef int Status;
using namespace std;
typedef struct QNode{
	int data;
	struct QNode *next;
}QNode,*QueuePtr;

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

Status InitQueue(LinkQueue &q){
	q.front = q.rear = new QNode;
	q.front->next = NULL;
	return 1;
}

Status EnQueue(LinkQueue &q,int e){
	QNode *p = new QNode;
	p->data = e;
	p->next = NULL;
	q.rear->next = p;
	q.rear = p;
	return 1;
}

Status DeQueue(LinkQueue &q,int &e){
	if(q.front == q.rear)
		return 0;
	QNode *p = q.front->next;	
	e = p->data;
	q.front->next = p->next;
	if(q.rear == p)
		q.rear = q.front;//          ,          
	delete p;
}

int GetHead(LinkQueue q){
	if(q.front != q.rear)
		return q.front->next->data;
	exit(-2);
}

void PrintQueue(LinkQueue q){
	if(q.rear == q.front)
		return ;
	q.front = q.front->next;
	while(1){
		cout<data<next;
	}
	cout<>n;
	 cout<>e;
	 	status = EnQueue(q,e);
	 	if(status)
	 		cout<>n;
	 for(int i=0;i

좋은 웹페이지 즐겨찾기