waiwai4701

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

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#include "stdafx.h"

#include <iostream>
using namespace std;

typedef int DataType;
#define SIZE 100

typedef struct {
	DataType data[SIZE];
	int head,tail;
}SqQueue;

//初始化
SqQueue init(SqQueue *Q)//顺序型数据结构,初始化之类的方法一定要有返回值
{
	Q = (SqQueue*)malloc(sizeof(SqQueue));
	if(Q==NULL) 
	{
		printf("%s","init failed");
		exit(0);
	}
	else
	{
		Q->data[0]=0;
		Q->head = 0;
		Q->tail = 0;
	}
	return *Q;
}
//判断是否为空
int isQempty(SqQueue *Q)
{
	if(Q->head == Q->tail) return 1;
	else return 0;
}
//判断是否满
int isQfull(SqQueue *Q)
{
	if(Q->tail == SIZE) return 1;
	else return 0;
}
//进
void inQueue(SqQueue *Q,DataType e)
{
	if(isQfull(Q) ==1) 
	{
		cout<<"full"<<endl;
			exit(0);
	}else
	{
		cout<<"q->tail"<<Q->tail<<endl;
		Q->data[Q->tail++] = e;//
		cout<<"not full"<<endl;
	}
	
}
//出
void outQueue(SqQueue *Q)
{
	if(isQempty(Q) == 1)
	{
		cout<<"out queue empty"<<endl;
		exit(0);
	}
	else
	{
		cout<<"out:"<<Q->data[Q->head++]<<endl;
	}
}



/*void main()
{
	SqQueue S;
	S=init(&S);
	cout<<"isempty"<<isQempty(&S)<<endl;
	inQueue(&S,1);
	cout<<"isempty"<<isQempty(&S)<<endl;
	inQueue(&S,2);
	cout<<"isempty"<<isQempty(&S)<<endl;
	outQueue(&S);
	
}*/

  

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