[問題] 關於Queue.Count==0的判斷問題已刪文
有個問題一直卡住想請教版上熱心的先進
假設我的Queue有100筆
我每次要取出30筆
1-30 31-60 61-90 91-100
^^^^^^當迴圈處理到取出第11筆時
Queue中沒有資料了會出現問題
故我加了一個判斷temp.count==0
結果跳出後
只印出Start & End這兩行
我看不見now peek=
Dequeue->
請問我該如何做呢??
程式碼如下:
Queue<int> temp = new Queue<int>();
richTextBox1.AppendText("Start Frequency output" + "\n");
for (int j = 0; j < 4; j++)
{
if (temp.Count == 0)
{
for (int i = 0; i < 30; i++)
{
richTextBox1.AppendText("now peek= " + Convert.ToString(temp.Peek()) + "\n");
richTextBox1.AppendText("Dequeue->" + temp.Dequeue() + "\n");
}
richTextBox1.AppendText("now peek= " + Convert.ToString(temp.Peek()) + "\n");
}
}
richTextBox1.AppendText("Start Frequency output End" + "\n");
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.146.10.115
推
08/31 11:06, , 1F
08/31 11:06, 1F
→
08/31 11:06, , 2F
08/31 11:06, 2F
→
08/31 11:08, , 3F
08/31 11:08, 3F
→
08/31 11:08, , 4F
08/31 11:08, 4F
→
08/31 11:20, , 5F
08/31 11:20, 5F
→
08/31 13:33, , 6F
08/31 13:33, 6F
→
08/31 14:49, , 7F
08/31 14:49, 7F
推
08/31 23:22, , 8F
08/31 23:22, 8F
→
08/31 23:23, , 9F
08/31 23:23, 9F
→
09/01 11:11, , 10F
09/01 11:11, 10F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):