請問資料結構stack/queue的問題QQ

2009-03-27 7:37 am
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.


麻煩各位幫忙解答,能的話盡量解釋一下,感謝

回答 (2)

2009-03-27 9:31 am
✔ 最佳答案
Assuming the following queue methods (functions) exist:
1. void enqueue( queue Q, data D)
This will put data D into queue Q.
2. data dequeue(queue Q)
This will return the first data from the queue Q and remove it from the queue.
3. bool is_empty(queue Q)
This will test if the queue Q is empty or not. If empty, true will be returned. If not, false will be returned.

The following is the pseudo code:

while is_empty(Q2) {
add_to_queue( Q1, dequeue(Q2));
} /* done */

2009-03-31 22:25:04 補充:
The code should be
while not is_empty(Q2)
2009-03-29 12:26 am
水~我看發問者也許不知道在說什


收錄日期: 2021-04-30 12:53:44
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090326000015KK11299

檢視 Wayback Machine 備份