waiwai4701

没有背后的一直努力,你的以为的隐忍不是隐忍,是懦弱。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#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);

}*/

  

posted on 2015-01-07 11:11  waiwai4701  阅读(98)  评论(0编辑  收藏  举报