📄 3.3.c
字号:
/*例3.3队列管理的模拟算法*/
#include <stdio.h>
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}QNode;
typedef struct
{
QNode *front,*rear;
}LQueue;
LQueue *Init_LQueue()
{
QNode *p;
LQueue *q;
p=(QNode *)malloc(sizeof(QNode));
q=(LQueue *)malloc(sizeof(LQueue));
p->next=NULL;
q->front=p;
q->rear=p;
return q;
}
void In_LQueue(LQueue *q,datatype x)
{
QNode *p;
p=(QNode *)malloc(sizeof(QNode));
p->data=x;
p->next=NULL;
q->rear->next=p;;
q->rear=p;
}
int Empty_LQueue(LQueue *q)
{
if(q->rear==q->front) return 1;
else return 0;
}
int Out_LQueue(LQueue *q,datatype *x)
{
QNode *p;
if(Empty_LQueue(q))
{
printf("队空");
return 0;
}
else
{
p=q->front->next;
q->front->next=p->next;
*x=p->data;
free(p);
if(q->front->next==NULL)
q->rear=q->front;
}
}
void outlinkqueue(LQueue *q)
{
QNode *p;
p=q->front;
printf("Queue:");
while(p!=q->rear)
{
p=p->next;
printf("%d\t",p->data);
}
printf("\n");
}
main()
{
LQueue *L;
datatype j;
L=Init_LQueue();
printf("请输入一个整数:");
scanf("%d",&j);
while(j!=0)
{
if(j%2==1)
In_LQueue(L,j);
else
Out_LQueue(L,&j);
outlinkqueue(L);
printf("请输入一个整数:");
scanf("%d",&j);
}
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -