首先我们分析由于只需要尾进尾出,用数组模拟更简单。

实现的功能如上图。
top可以表示栈中元素个数。
capacity表示栈的容量。
首先是堆的初始化

再就是栈的插入和删除


然后实现显示栈顶元素

大小和检测是否为空的实现

销毁栈的实现(防止内存泄露)

下面是队列的实现
由于需要头出尾入,所有用链表实现更好。


为了避免每一次调用的时候还要输入头,尾指针,直接进行打包成结构体。
初始化的实现

尾插的实现。

尾删的实现。

整个队列销毁的实现

然后我们就要实现队列的头显和尾显已经判断是否为空的实现。

最后就是判断队列大小的实现。
