⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.c

📁 以C8051F020单片机做的多功能计数器
💻 C
字号:
#include "queue.h"

extern xdata double dCounter;;
extern uchar MeasureType;

void InitQueue(struct sqqueue *p) /*初始化队列*/
{
	p->front=0;
	p->rear=0;
}
bit EnQueue(struct sqqueue *q, double e1,uchar e2;); /*入队*/
{
	if((q->rear+1)%maxsize==q->front)//判断队列是否满
	return 0;
	else
	q->Counter[q->rear]=e1;//加入一个新的数据
	q->type[q->rear]=e2;//加入一个新的数据
	q->rear=(q->rear+1)%maxsize;//将队尾数加1
	return 1;
}
void DeQueue(struct sqqueue *q)/*出队*/
{
	
	if (q->front==q->rear)//判断队列是否为空
		MeasureType=0;
	else
	{
		e1=q->Counter[q->front];//提出队首数据
		e2=q->type[q->front];//提出队首数据
		q->front=(q->front+1)%maxsize;//改变队首
	}
}
bit Empty(struct sqqueue *q)/*判断队列是否空*/
{
	bit v;
	if (q->front==q->rear)//判断队列是否为空,
	v=1;
	else
	v=0;
	return v; 
}

/*
unsigned char QueueFront(struct sqqueue *q)//获得队首元素
{
	unsigned char e;
	if (q->front==q->rear) //判断队列是否为空
	e=1;
	else
	e=q->hisData[q->front];
	return e;
}
unsigned char QueueBack(struct sqqueue *q)
{
	unsigned char e;
	if(q->front == q->rear)
		e = -1;
	else 
		e = q->hisData[q->rear-1];
	return e;
}
void Display(struct sqqueue *q)//从队首到队尾显示队列中的元素
{
	unsigned char s;
	s=q->front;
	//printf("队列中的元素为:\n");
	if (q->front==q->rear)
	//printf("队列为空!");
	else
	{
		while(s<q->rear)
		{
		//printf(" %d <-", q->hisData[s]);
		s=(s+1)%maxsize;
		}
		//printf("\n");
	}
}


void queue()
{
	struct sqqueue queue,*head;
	int x,y,select;
	char ch='y';
	head=&queue;
	InitQueue(head);
	//printf("一个空队列已经创建!\n");
	while(ch=='y' || ch=='Y')
	{
	//printf("1: 入队列 \n");
	//printf("2: 出队列 \n");
	//printf("3: 判断队列是否空 \n");
	//printf("4: 取队首元素 \n");
	//printf("5: 取队尾元素 \n");
	//printf("6: 显示队列\n");
	//printf("请选择功能 (1~4):");
	scanf("%d",&select);
	switch(select)
	{
		case 1:
		{ 
		//printf("请输入一个值: ");
		scanf("%d",&x);
		EnQueue(head,x);
		Display(head);
		break;
		}
		case 2:
		{
		DeQueue(head);
		Display(head);
		break;
		}
		case 3:
		{
		if(Empty(head))
		//printf("队列为空\n");
		else
		//printf("队列不空\n");
		break;
		}
		case 4:
		{
		y=QueueFront(head);
		if(y)
		//printf("队列为空");
		else
			//printf("队首元素为: %d\n",y);
		Display(head);
		break;
		}
		case 5:
		{
			y = QueueBack(head);
			if(y == -1)
				//printf("队列为空\n");
			else
				//printf("队尾元素为: %d\n",y);
			Display(head);
			break;
		}
		case 6:
		{
			Display(head);
		}
	}
	//printf("是否继续?(y/n)");
	fflush(stdin);
	ch=getchar();
	}
}


void main()
{
  queue();
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -