算法:C语言实现 (4)队列的数组实现

#include <stdlib.h>
#include "Item.h"

static Item *q;
static int N, head, tail;

void QUEUEinit(int maxN)
{
    q = (Item *)malloc((maxN+1)*sizeof(Item));
    N = maxN+1;
    head = N;
    tail = 0;
}

int QUEUEempty()
{
    return (head%N == tail);
}

void QUEUEput(Item item)
{
    q[tail++] = item;
    tail = tail%N;
}

Item QUEUEget()
{
    head = head %N;
    return q[head++];
}
原文地址:https://www.cnblogs.com/dLong/p/3433338.html