English 中文(简体)
理解格乌埃/斯特克班是如何运作的,并解释为什么该守则是行之有效的
原标题:Understanding how queue/stack class works and figuring out why this code isn t working
  • 时间:2012-01-13 00:13:40
  •  标签:
  • c#

第一种 for法有几处错误。 我可以说明为什么而且似乎喜欢工作。

foreach - Disability token foreach in category, sruct, orring member declaration.

页: 1

第2条每种方法。 这项工作如何? 我认为,它只是按时序逐个编号。 混淆之处在于,它是相同的法典,但不是 que。 第2版每版4 3 2。 为什么如此?

namespace Cards
{
    class Class1
    {
        Queue numbers = new Queue();

        foreach (int number in new int[4]{1,2,3,4})
        {
             numbers.Enqueue(number);
            Console.WriteLine(number + " has joined the queue");
        }
        foreach (int number in numbers)
        {
             Console.WriteLine(number);
        }
        while(numbers.Count > 0)
        {
            int number = (int)numbers.Dequeue();
            Console.WriteLine(number + " has left the queue");
        }
    }

}
最佳回答

该法典必须采用一种方法。

class Class1
    {
        public void DoQstuff()
        {
          Queue numbers = new Queue();

          foreach (int number in new int[4]{1,2,3,4})
          {
              numbers.Enqueue(number);
              Console.WriteLine(number + " has joined the queue");
          }
          foreach (int number in numbers)
          {
              Console.WriteLine(number);
          }
          while(numbers.Count > 0)
          {
              int number = (int)numbers.Dequeue();
              Console.WriteLine(number + " has left the queue");
          }
        }
    }

如果管理起来,则按预期操作。

询问工作,首先是......。

首先,最后一点是,打工是头一件事,因此这将是最后一件事。

同样,如果你在一家咖啡店工作,你必须等到您的轮椅上来,先在座的人就是第一位。

摇篮就像相互争 books的书籍一样。 ......在你放弃所有事情之前,你可以首先拿走。

问题回答

st不与 que一样。 在一个问题中,首先是什么。 在一栏中,你重新审视了劳工组织(第一次,最后)。

因此,你看到情况正好相反,即4,3,2,1。

Well! In your second loop you are trying to print all the elements in the collection. 1) In case of Queue the objects are stored as it is added. So you get the same answer like in your first loop (FIFO) 2) In case of Stack the objects will be stored in the reverse order so when you pop the object from the collection you can remove the last object which you inserted. (LIFO)

希望这一帮助。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签