// Filename : list_queue.c
// Authot : LupingChen
// Data : 2014.06.01
// Content : main\clear
#include <stdio.h>
#include <stdlib.h>
//定义节点数据类型
typedef struct Node {
int data;//节点数据
struct Node* next;//记录下一节点地址
} Node;
//定义队列数据类型
typedef struct {
Node* head;//头指针
}
//清除队列所有元素
void clear(Queue* pq);
int main(void)
{
push(&queue, 11);
travel(&queue);
push(&queue, 22);
travel(&queue);
push(&queue, 33);
travel(&queue);
printf("%s\n", empty(&queue)?"队列为空":"队列没空");
printf("%s\n", full(&queue)?"队列为满":"队列没满");
printf("-----------------------------------------\n");
travel(&queue);
printf("出队元素是%d\n",pop(&queue));
printf("队首元素是:%d\n", get_head(&queue));
printf("队尾元素是:%d\n", get_tail(&queue));
printf("队列元素个数是:%d\n", size(&queue));
clear(&queue);
return 0;
}
//清除队列所有元素
void clear(Queue* pq)
{
while (pq->head != NULL)
{
Node* p = pq->head;
pq->head = p->next;
free(p);
p = NULL;
}
}
队列的链式存储结构的实现3——完结编
最新推荐文章于 2024-05-26 19:24:51 发布