Queues and stacks

Queues and stacks are collection items that allow us to save data temporarily during the execution of the program. These collections are very similar to the other collections, such as lists, with the major difference being how elements are added and removed from the collection.

A queue is a first-in, first-out type of collection. It basically implies that elements are accessed from the queue in the same order they are added to the collection. When the items are accessed, they can also be removed in the same operation. A queue has three main operations:

  • Adding a new element to the queue: It's executed by the Enqueue method.
  • Removing an existing element from the queue: It's executed by the Dequeue method.
  • Peeking or retrieving ...

Get Programming in C#: Exam 70-483 (MCSD) Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.