‫In this lesson, we will talk about stacks and Qs.
‫Stacks and Qs are data structures in computer science.
‫A data structure is a data organization, management and storage format that enables efficient access
‫and modification.
‫Each data structure has a unique way of storing and managing the data we insert into it.
‫There are many different types of data structures, but in this lesson we will look at two that are
‫very common and come in handy when we want to deal with data in some scenarios.
‫The first data structure we will talk about is the stack from its name.
‫A stack stores the data in the form of a stack.
‫If we look at this picture of the rock stacked on top of each other, we can easily take the first rock
‫without causing a stack of rocks to fall.
‫But it's impossible to take out the ones in the middle.
‫We can easily take the first rock without causing the stack of rocks to fall, but it's impossible to
‫take out the ones in the middle.
‫So it's first come last out or last in.
‫First out a stack basically adds and removes data from the top only.
‫So this concept stacks are usually or very often used in mathematical algorithms and in data management
‫by the operating systems.
‫So some examples on using stacks that we might face are, for example, reversing data.
‫So for reversing data or numbers using a stack, it is very simple.
‫If we just take the input from the user, for example, and store it in a stack, then start removing
‫data from the stack from top so that the data will get reversed.
‫So then there are browser back buttons, for example.
‫So while watching tutorials and tutorials you, your browser will save the website slash web pages you
‫clicked on and pressing the back button will load the last page you went to.
‫And then the one before it, which hereby is a textbook example of one, is that can come in handy.
‫And then there are also the undo and redo buttons that you have in many applications where you have
‫a stack basically storing what was performed and then undoing that performed action.
‫So both stacks and Q's are collections like lists and dictionaries.
‫Stacks have their own unique operations that we can use, for example, to manipulate and manage the
‫data.
‫And they store the ones that we're going to look at are going to be pushed.
‫So using the push method, we can add data to the stack.
‫Of course, the data will always be added on top.
‫Then we have pop and using the pop method we can remove data from the top of the stack.
‫And finally we have the peek method which will return the object data on top of the stack without removing
‫it.
‫So then there are queues and choose are another type of data structures that is commonly used in programming
‫QS work like real Qs in real life, like an airport check in where the first person in the front desk
‫gets served first, or like in a restaurant drive thru where the car in the front will get to order
‫first and when new cars come in they must wait in the back of the line and we'll be last served.
‫So we use Qs when the order the data comes in is important.
‫So data can be added only from the back and removed from the front and can't access the elements in
‫the middle.
‫It's the FIFO system.
‫So first in, first out, for example in operating systems, queuing messages, IO requests, mouse
‫movements and so forth so they can be executed in the order they came in.
‫Then managing web requests and a server to handle them one by one.
‫So it's a handle congestion and queuing input in video games, for example, and a fighting game with
‫combo attacks like Street Fighter, where you have to keep track of the user input to determine the
‫combo that will be performed.
‫Jews have their own unique operations that we can do on them to manipulate or manage the data they store.
‫For example, using the NQ method, we can add data to the queue.
‫Of course the data will be always added to the back of the queue, so it will be rare.
‫So at the rear, so to speak.
‫Then we have the queue method.
‫We can remove data from the front of the queue using the queue method.
‫And finally we have the peak method which will return the object or data in the front of the queue without
‫removing it.
‫So you're just peeking in, but you're not doing anything else with it, just looking what is there?
‫And then you can use it.
‫So next we are going to look at how we can actually implement and use stacks and queues in C-sharp.