?? queue.c
字號(hào):
#include "queue.h"
extern xdata double dCounter;;
extern uchar MeasureType;
void InitQueue(struct sqqueue *p) /*初始化隊(duì)列*/
{
p->front=0;
p->rear=0;
}
bit EnQueue(struct sqqueue *q, double e1,uchar e2;); /*入隊(duì)*/
{
if((q->rear+1)%maxsize==q->front)//判斷隊(duì)列是否滿
return 0;
else
q->Counter[q->rear]=e1;//加入一個(gè)新的數(shù)據(jù)
q->type[q->rear]=e2;//加入一個(gè)新的數(shù)據(jù)
q->rear=(q->rear+1)%maxsize;//將隊(duì)尾數(shù)加1
return 1;
}
void DeQueue(struct sqqueue *q)/*出隊(duì)*/
{
if (q->front==q->rear)//判斷隊(duì)列是否為空
MeasureType=0;
else
{
e1=q->Counter[q->front];//提出隊(duì)首數(shù)據(jù)
e2=q->type[q->front];//提出隊(duì)首數(shù)據(jù)
q->front=(q->front+1)%maxsize;//改變隊(duì)首
}
}
bit Empty(struct sqqueue *q)/*判斷隊(duì)列是否空*/
{
bit v;
if (q->front==q->rear)//判斷隊(duì)列是否為空,
v=1;
else
v=0;
return v;
}
/*
unsigned char QueueFront(struct sqqueue *q)//獲得隊(duì)首元素
{
unsigned char e;
if (q->front==q->rear) //判斷隊(duì)列是否為空
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)//從隊(duì)首到隊(duì)尾顯示隊(duì)列中的元素
{
unsigned char s;
s=q->front;
//printf("隊(duì)列中的元素為:\n");
if (q->front==q->rear)
//printf("隊(duì)列為空!");
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("一個(gè)空隊(duì)列已經(jīng)創(chuàng)建!\n");
while(ch=='y' || ch=='Y')
{
//printf("1: 入隊(duì)列 \n");
//printf("2: 出隊(duì)列 \n");
//printf("3: 判斷隊(duì)列是否空 \n");
//printf("4: 取隊(duì)首元素 \n");
//printf("5: 取隊(duì)尾元素 \n");
//printf("6: 顯示隊(duì)列\(zhòng)n");
//printf("請(qǐng)選擇功能 (1~4):");
scanf("%d",&select);
switch(select)
{
case 1:
{
//printf("請(qǐng)輸入一個(gè)值: ");
scanf("%d",&x);
EnQueue(head,x);
Display(head);
break;
}
case 2:
{
DeQueue(head);
Display(head);
break;
}
case 3:
{
if(Empty(head))
//printf("隊(duì)列為空\n");
else
//printf("隊(duì)列不空\n");
break;
}
case 4:
{
y=QueueFront(head);
if(y)
//printf("隊(duì)列為空");
else
//printf("隊(duì)首元素為: %d\n",y);
Display(head);
break;
}
case 5:
{
y = QueueBack(head);
if(y == -1)
//printf("隊(duì)列為空\n");
else
//printf("隊(duì)尾元素為: %d\n",y);
Display(head);
break;
}
case 6:
{
Display(head);
}
}
//printf("是否繼續(xù)?(y/n)");
fflush(stdin);
ch=getchar();
}
}
void main()
{
queue();
}*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -