题目描述
解题思路
这道题的思路就是使用两个队列来实现
入栈就是入队列
出栈就是将非空队列的前n-1个元素移动到新的队列中去
再将最后一个元素弹出
动画详解
代码实现
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
typedef int QDataType;
typedef struct QueueNode
{
struct QueueNode* next;
QDataType x;
}QNode;
// 使用另一个结构体来存储头尾指针,指向队列的头尾
typedef struct Queue
{
QNode* phead;
QNode* ptail;
int size;
}Queue;
void QueueInit(Queue* pq)
{
assert(pq);
pq->