From 2d51df1f31d14c7a8ea246d24b96fde350824255 Mon Sep 17 00:00:00 2001 From: ParkMoonJ Date: Thu, 8 Apr 2021 18:37:10 +0800 Subject: [PATCH] =?UTF-8?q?Update=203=20=E6=A0=88=E5=92=8C=E9=98=9F?= =?UTF-8?q?=E5=88=97.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3 栈和队列/3 栈和队列.md | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/3 栈和队列/3 栈和队列.md b/3 栈和队列/3 栈和队列.md index c4a53b2..6118c72 100644 --- a/3 栈和队列/3 栈和队列.md +++ b/3 栈和队列/3 栈和队列.md @@ -270,7 +270,7 @@ void main() { ``` ```cpp -<< ar +<< char ``` ### 3.13 简述以下算法的功能(栈和队列的元素类型均为 `int`)。 @@ -281,18 +281,33 @@ void algo3(Queue &Q) { int d; InitStack(S); while (!QueueEmpty(Q)) { - DeQueue(Q, d); - Push(S, d); - } + DeQueue(Q, d); // 队首元素返回给 d + Push(S, d); // d 入栈 + } // 依次入栈 while (!StackEmpty(S)) { - Pop(S, d); - EnQueue(Q, d); - } -} + Pop(S, d); // 栈顶元素返回给 d + EnQueue(Q, d); // d 入队 + } // 依次入队 +} // 倒置队列 ``` ### 3.14 若以 1234 作为双端队列的输入序列,试分别求出满足以下条件的输出序列: +``` +PPPPLLLL // 1234 输入受限 输出受限 +PPPPLLLR // 1234 输入受限 +PPPPLLRL // 1243 输入受限 +PPPPLRLL // 1423 输入受限 +PPPPRLLL // 4123 输入受限 +PPPPLLRR // 1243 输入受限 +PPPPLRLR // 1423 输入受限 +PPPPLRRL // 1432 输入受限 +``` + +``` +1234 PPPPLLLL PPPPLLLR QQQQRRRR +``` + #### (1)能由输入受限的双端队列得到,但不能由输出受限的双端队列得到的输出序列; #### (2)能由输出受限的双端队列得到,但不能由输入受限的双端队列得到的输出序列;