2016-12-05 157 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