栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

队列之C语言

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

队列之C语言

#include 
#include 

#define   QUEUESIZE   128



struct queue
{
	unsigned char buff[QUEUESIZE];
	int front;
	int tail;
};

void  QueueInit(struct queue *queue_t)
{
	memset(queue_t,0,QUEUESIZE);
	queue_t->front=0;
	queue_t->tail=0;
}
int  QueueIsEmpty(struct queue * queue_t )
{
	return    queue_t->tail==queue_t->front;
}
int QueueisFull(struct queue * queue_t)
{
	return  queue_t->tail >= QUEUESIZE;
}
int QueueInsert(struct queue *queue_t , unsigned  char  word)
{
	if(!QueueisFull(queue_t)){
		queue_t->buff[queue_t->tail] = word;
		queue_t->tail++;
	}else
	{
		printf("Queue is Full n");
		return -1;
	}
}
int QueueGetData(struct queue * queue_t )
{
	if(!QueueIsEmpty(queue_t))
	{		
			return queue_t->buff[queue_t->front++];
	}else{
		  printf("Queue is Empty !n");
		  return -1;
	}
}
int QueueGetCount(struct  queue  *  queue_t )
{
	return  queue_t->tail -  queue_t -> front ;
}

int main(int argc ,char ** argv )
{
	int index=0;

	struct  queue  queue_p;

	QueueInit(&queue_p);
	
	QueueInsert(&queue_p,22);
	QueueInsert(&queue_p,23);
	QueueInsert(&queue_p,24);
	QueueInsert(&queue_p,25);
		
	printf("count == %d  n",index=QueueGetCount(&queue_p ));
	
	while(index--)   printf("data =  %d  n",QueueGetData(&queue_p));
		
	printf("count == %d  n",index=QueueGetCount(&queue_p ));

	
	return 0;

}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/997246.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号