看板 Grad-ProbAsk 關於我們 聯絡資訊
10. When an array of size n is used to implement a circular queue and we would like to utilize all the n spaces in the array. which of the following may be an illegal operation? A. an enqueue when front = rear B. a dequeue when front = rear C. an enqueue when rear = 0 D. all of the above E. none of the above 這題給的答案是 C (1)想請問queue 在初值設定不是把rear, front設成0嗎? 再enqueue東西好像也合法才對吧? (2) A和B為什麼對? 利用n格的circular queue設定 if(front==rear) and (tag==true) return "Q full" if(front==rear) and (tag==false) return "Q Empty" 如果tag==true 不就不合法了嗎 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.169.232.3
ab170926:(rear+1)%n == front 才是full 01/12 22:41
ab170926:我是覺得B是錯的 01/12 22:43
s07021990:初值時 rear是NULL 當enqueue時變第一個 01/12 23:11
s07021990:表示當rear不為NULL時,是有元素的 01/12 23:12
s07021990:因此may be an illegal 01/12 23:13