📄 test04.txt
字号:
#include <stdio.h>
#include <malloc.h>
typedef int Elemtype;
typedef struct NODE
{
Elemtype data;
struct NODE *next;
}SNode;
typedef struct
{
SNode *front;
SNode *rear;
}LQueue;
void InitQueue(LQueue *&q)
{
q = (LQueue*)malloc(sizeof(LQueue));
q->front = q->rear = NULL;
}
void EnQueue(LQueue *&q, Elemtype x)
{
SNode *s;
s = (SNode*)malloc(sizeof(SNode));
s->data = x;
s->next = NULL;
if (q->rear == NULL)
{
q->front = s;
q->rear = s;
}
else
{
q->rear->next = s;
q->rear = s;
}
}
int DelQueue(LQueue *&q, Elemtype &x)
{
SNode *p;
if (q->front == NULL)
{
return 0;
}
else
{
x = q->front->data;
p = q->front;
if (q->front == q->rear)
{
q->front = NULL;
q->rear = NULL;
}
else
{
q->front = q->front->next;
}
free (p);
}
return 1;
}
void Display(LQueue *q)
{
printf("出栈显示");
while (q->front != NULL)
{
int x;
DelQueue(q, x);
printf("%d-->", x);
}
}
void main()
{
int i;
LQueue *q = NULL;
InitQueue(q);
printf("入队显示");
for (i=0; i<10; i++)
{
EnQueue(q, i);
printf("%d-->", i);
}
EnQueue(q, 10);
printf("%d", i);
printf("\n");
//显示出队
Display(q);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -