标签:
#include "stdafx.h" #include <iostream> using namespace std; typedef int DataType1; typedef struct qnode{ DataType1 data; struct qnode *next;//在结构体中调用结构体本身,要用qnode,也就是括号前的名字 }QNode,*linkQ; typedef struct { linkQ front;//头节点 linkQ rear;//尾节点 }LinkQueue; void initLQ(LinkQueue *Q) { //初始化头节点 Q->front = (linkQ)malloc(sizeof(QNode)); if(!Q->front) exit(0); Q->rear = Q->front; Q->front->next = NULL; } void inQueue1(LinkQueue *Q,DataType1 e) { linkQ p; p = (linkQ)malloc(sizeof(QNode)); if(!p) exit(0); p->data = e; p->next = NULL; Q->rear->next = p; Q->rear = p; } void outQueue1(LinkQueue *Q) { linkQ p; if(Q->front == Q->rear) { cout<<"queue is empty"<<endl; exit(0); } p=Q->front->next; cout<<"out:"<<p->data<<endl; Q->front->next = p->next; if(Q->rear == p) Q->rear = Q->front; free(p); } /*void main() { LinkQueue Q ; initLQ(&Q); inQueue1(&Q,1); inQueue1(&Q,2); outQueue1(&Q); outQueue1(&Q); }*/
标签:
原文地址:http://www.cnblogs.com/waiwai4701/p/4207942.html