作者acireme (..............)
看板C_and_CPP
标题[问题] 两题计算机的题目
时间Wed Mar 25 23:52:45 2009
这是我门老师出的作业,这两题我看不懂,麻烦有谁可以交我吗
(1)
write an algorithm segment using while loops to copy the contents of
stack S1 to stack S2.
Input: Source stack (s1) and destination stack (s2)
1. Allocate memory for a temporary stack (Temp)
2. While s1 is not empty
2.1 push ( Temp, pop(s1) )
End loop
3. While Temp is not empty
3.1 TempValue = pop(Temp)
3.2 push ( s1, TempValue )
3.3 push ( s2, TempValue )
(2)
use while loops to concatenate the contents of queue Q2 and the contents
of queue Q1. After the concatenation, the elements of queue Q2 should be
at the end of the elements of queue Q1. Queue Q2 should be empty.
Input: Source queue (q2) and destination queue (q3)
1. Allocate memory for a temporary queue (Temp)
2. While q2 is not empty
2.1 enqueue ( Temp, dequeue(q2) )
End loop
3. While Temp is not empty
3.1 TempValue = dequeue(Temp)
3.2 enqueue ( q2, TempValue )
3.3 enqueue ( q3, TempValue )
End loop
End
在此放上我的答案,麻烦帮我看看,感谢了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.170.97.24
1F:→ james732:1. 写个while回圈复制 stack S1 至 S2 03/25 23:56
2F:→ james732:2. 写个while回圈把queue Q2的内容都移到queue Q1的尾端 03/25 23:56
※ 编辑: acireme 来自: 118.170.97.24 (03/26 00:09)
3F:推 aecho:3.2不对吧 Queue Q2 should be empty. 03/26 08:17
4F:→ acireme:谢谢啦 03/26 17:36