数据结构伪代码的实现(队列篇)

数据结构伪代码的实现(队列篇)
以循环队列为例

#include<stdio.h>
#include<malloc.h>
#include<stdbool.h>
#define MAXSIZE 6 
/*
    定义数组最大长度 
    接下来有很多操作都是对MAXSIZE取余
    这是一个循环队列 
    当队列满的时候需要 需要将队尾指向对头
    例判断队列是否已满:
    if((pQ->rear+1)%MAXSIZE==pQ->front)
*/
typedef struct Queue
{
    int *pBase;//新建数组的首地址
    int front;
    int rear;
}QUEUE;

void init(QUEUE *);
bool en_queue(QUEUE *,int );
bool full_queue(QUEUE*);
void traverse_queue(QUEUE *);
bool out_queue(QUEUE *,int *);
bool empty_queue(QUEUE *);

int main(void)
{
    QUEUE Q;
    int val;

    init(&Q);//创建队列  初始化front和rear
    if(empty_queue(&Q))
        printf("队列为空!\n");
    printf("插入数:\n");
    en_queue(&Q,1);
    en_queue(&Q,2);
    en_queue(&Q,3);
    en_queue(&Q,4);
    en_queue(&Q,5);
    en_queue(&Q,6);
    if(empty_queue(&Q))
        printf("队列为空!\n");
    traverse_queue(&Q);
    i
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值