[데이터 구조] 체인 팀 (큐 의 체인 저장)
typedef struct LinkNode{
ElemType data;
struct LinkNode *next;
}LinkNode;
typedef struct{
LinkNode *front;
LinkNode *rear;
}LinkQueue;
전체적인 디자인 은 다음 과 같다.
#include
#include
#include
using namespace std;
typedef int ElemType;
typedef struct LinkNode{
ElemType data;
struct LinkNode *next;
}LinkNode;
typedef struct{
LinkNode *front;
LinkNode *rear;
}LinkQueue;
void InitQueue(LinkQueue &Q); //
bool QueueEmpty(LinkQueue &Q); //
void EnQueue(LinkQueue &Q,ElemType &x); //
bool DeQueue(LinkQueue &Q,ElemType &x); //
int main()
{
return 0;
}
void InitQueue(LinkQueue &Q){
Q.front=Q.rear=(LinkNode*)malloc(sizeof(LinkNode));
Q.front->next=NULL; //
}
bool QueueEmpty(LinkQueue &Q){ //
if(Q.front==Q.rear)
return true;
else
return false;
}
void EnQueue(LinkQueue &Q,ElemType &x){
LinkNode *p;
p=new LinkNode; // p ,
p->data=x;
p->next=NULL;
Q.rear->next=p; //
Q.rear=p;
}
bool DeQueue(LinkQueue &Q,ElemType &x){
if(Q.front==Q.rear)
return false;
LinkNode *p;
p=Q.front->next;
x=p->data;
Q.front->next=p->next;
if(Q.rear==p) //
Q.rear=Q.rear; //
free(p);
return true;
}