首页 > 代码库 > 线性队列

线性队列

#include "stdafx.h"#include <iostream>using namespace std;typedef int DataType;#define SIZE 100typedef 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);	}*/

  

线性队列