队列的链式存储结构的实现3——完结编

//  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;
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值