Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 30 / 68

Stacks and queues (the basics of data structures)

This lesson covers VB.NET's Stack and Queue, with the aim of understanding how to add and remove data for different purposes.

Stack(Of T) takes out the value put in most recently (last in, first out); Queue(Of T) takes out the value put in first (first in, first out). Picture a pile of things against a line of people waiting.

The sample code pushes "A" then "B" with stack.Push(...) and watches stack.Pop() hand back "B" first, while queue.Enqueue() followed by queue.Dequeue() hands back "A" first.

A common early stumble is that the two hand items back in opposite orders. Picture a pile of blocks — you take from the top — against a queue, where the front is called first.

In professional work, a Stack tracks the history behind an undo operation, while a Queue manages print jobs and task ordering — each playing to its own character.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)