首页 > 代码库 > 链式队列

链式队列

#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 = http://www.mamicode.com/e;"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);}*/

  

链式队列