2016-12-05 123 views
-6

需要在每個隊列中創建4個數組的隊列。C中的隊列隊列#

喜歡的東西:

Queue1[1] {int i1, int i2, int i3, int4} 
Queue1[2] {int i1, int i2, int i3, int4} etc.. 

同爲隊列2

~~編輯~~

我想跟蹤,隨機生成的整數的。 使用帶有對象的鏈接列表結束。 所以我創建了一個包含我想要的所有整數的對象,然後調用一個鏈表。

LinkedList<RandomInts> Q = new LinkedList<RandomInts>(); 

使用:

Q.ElementAt(indexOfObject).Whatever(); 

的伎倆就好了。謝謝!

+1

你熟悉的問候術語'new'創造和預先定義數組的大小..?這是谷歌是在那裏..請做谷歌搜索'隊列...等' – MethodMan

+0

你有問題嗎? – Plutonix

+0

爲什麼你使用一個隊列,如果你知道每次都會有4個整數,爲什麼不使用一個數組陣列 –

回答

0

這其實很簡單。整數的隊列與任何其他類型的隊列沒有什麼不同。您可以輕鬆地擁有一個列表隊列或一個隊列隊列或類似的東西。

我正在使用接受IEnumerable的隊列構造函數來初始化這些。在第一種情況下,我從一個int數組構成一個隊列。

在第二種情況下,我從一個int數組構建一個隊列。我表明,作爲一個例子,因爲它不清楚你的帖子,你實際上需要陣列的隊列。如果每個隊列只包含四個整數,爲什麼不創建隊列中有四個整數?爲什麼要麻煩整個隊列的事情呢?

無論哪種方式,這裏的德codez:

 // Here you have it - a queue of arrays 
     // Really, it's no different than a queue of any other type 
     Queue<int[]> queue = new Queue<int[]>(
      // Construct the queue from the following array of arrays 
      new[] 
      { 
       new[] { 3, 2, 1, 0 }, 
       new[] { 32, 24, 234, 3 } 
       // Whatever you want 
      } 
     ); 

     // If all you want is a queue with four ints, why bother with the queue of array thing? 
     // You can initialize a queue with some numbers like this 
     Queue<int> queueOfInts = new Queue<int>(new[] { 3, 2, 1, 0 }); 
+0

我結束了使用由對象組成的鏈接列表。 LinkedList q = new LinkedList (); 使用q.ElementAt(indexOfObj).Whatever();訣竅。謝謝!! – supItsMe