作者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