📄 3-3-2-1.txt
字号:
/*链队的基本运算与实现*/
#include <stdio.h>
#include <malloc.h>
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}QNode;
typedef struct
{
QNode *front,*rear;
}LQueue;
void menu();
LQueue *Init_LQueue();
void In_LQueue(LQueue *q,datatype x);
int Empty_LQueue(LQueue *q);
int Out_LQueue(LQueue *q,datatype *s);
void main()
{
int n,m=1;
LQueue *Q=NULL;
/*clrscr();*/
while(m)
{
menu();
scanf("%d",&n);
switch(n)
{
case 1: Q=Init_LQueue();
break;
case 2:{
datatype x;
QNode *p;
printf("please input a value x:\n");
scanf("%d",&x);
In_LQueue(Q,x);
p=Q->front->next;
while(p!=NULL)
{
printf("%5d",p->data);
p=p->next;
}
break;
}
case 3:{
int flag;
QNode *p;
flag=Empty_LQueue(Q);
p=Q->front->next;
if(flag!=1)
{
while(p!=NULL)
{
printf("%5d",p->data);
p=p->next;
}
}
else
printf("queue empty!\n");
break;
}
case 4:{
int flag;
datatype x,*s;
QNode *p;
s=&x;
flag=Out_LQueue(Q,s);
p=Q->front->next;
if(flag==1)
{
while(p!=NULL)
{
printf("%5d",p->data);
p=p->next;
}
printf("\n%5d\n",x);
}
else
printf("queue empty!\n");
break;
}
case 0:m=0;
}
}
}
void menu()
{
/*clrscr();*/
printf("\n");
printf("\t\t1.jian you tou jie dian queue\n\n");
printf("\t\t2.into queue\n\n");
printf("\t\t3.empty queue\n\n");
printf("\t\t4.out queue\n\n");
printf("\t\t0.exit\n\n");
printf("\n\n\n\tplease select:");
}
LQueue *Init_LQueue()
{
LQueue *q;
QNode *p;
q=(LQueue*)malloc(sizeof(LQueue));
p=(QNode*)malloc(sizeof(QNode));
p->next=NULL;
q->front=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->front==q->rear)
return 1;
else
return 0;
}
int Out_LQueue(LQueue *q,datatype *s)
{
QNode *p;
if(Empty_LQueue(q)==1)
{
return 0;
}
else
{
p=q->front->next;
q->front->next=p->next;
*s=p->data;
free(p);
if(q->front->next==NULL)
q->rear=q->front;
return 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -