 Hello, everyone. In this video, we are going to see Q in collections. So, we have already seen various types of collections like we have seen ArrayList, we have seen Stack. Now, similarly, we will be working with Q in collections. Now, what is the learning outcome in this particular video? At the end of the video, students will be able to describe Q along with various methods and students will be able to write a program using Q in collections, okay. Let us see one by one. Now, what is Q? Why it is required? Q works on the principle of first in first out, that is the element which enters first will be deleted first. So, everyone might be aware with this concept, but the same can be implemented in .NET. So, to enqueue an item into a list, what is the meaning of it? The meaning of this is to add an element into the list that we call a technically term as enqueue, okay. Similarly, we have a DQ. What is DQ? An item that has to be removed. DQ is to remove an element from the list, okay. Now, adder system.collections is a namespace under which all types of collections are present. Same Q is also present inside the system.collections environment. Q's constructs are similar to that of arelist and stack. We have already seen how we have created arelist, how we create stack. Similarly, we will be creating for Q. We have seen various we versions how we create arelist like we can create an empty arelist, we can create an arelist with a particular size, we can create same with stack, okay. Same can be done with Q. Now, what are the steps to create a Q? There are various types to create a Q. First, let us say with empty, Q object equal to new Q, where I am passing nothing. It is blank. We call it as an empty object creation, okay. Another way to create a Q is with some kind of capacity, initial capacity. Here, I am passing a capacity of 13, okay. It can be anything. In collections, in .NET, it is very important to note that whatever capacity we are passing, it is immaterial. It does not depend at all on it. It is just for referencing that, okay, I might have 13 elements, but it is not a restriction that your element should be 13, your element should be less than 13 or your element should be more than that. There is no such restriction. Any number of elements can be entered into this particular object. It is irrelevant how many elements you are going to enter. But still, to have an initial judgment, we will give some size. That is it. Another way to create a collection is passing the object of another collection itself. Now, Q object, likely we might have created an object Q object one equal to new Q. That object one can be passed directly as a parameter over here. So, I can write instead of my collection object one, which is an object of Q. So, likewise, we can have many objects of Q and we can pass objects directly without worrying about elements, okay. So, objects can be copied from one collection to another collection. Let a simple Q program using collection. Let us work with a sharp develop and try to solve it. We will come to sharp develop. So, as I explained in earlier videos, how you will start with the program file new solution. Take a console application, give the program name. I will give it as Q demo. No space should be there. Q demo, okay. Create. When I click on create, a program will be created, okay. These are all comments. Let us delete it so that it becomes more visible. And this is unwanted section which comes automatically in sharp develop. Let us remove it, okay. So that we can focus on the exact program. Now, here as I said that namespace required is using system.collections. This is very different. So, all your collections are present inside this particular namespace collection. So, stack, Q, ArrayList, any type are all present inside this collections, okay. Now, as I explained, there are various ways I can create a Q, okay. So, first let us start with simple Q object equal to new Q, okay. Let us make it empty. This is what object of Q is created at this particular line, okay. Now, if I want to enter an element into or add an element to this particular Q, I can do it using methods inside Q. What popular methods we have inside Q, what is NQ and there is DQ, okay. So, let us NQ it, object dot, sorry, object dot NQ. So, let us put 10 into it. You can put any object, okay. I am putting some integer values, object dot NQ 20, object dot NQ 30, okay. This is how elements are added. Now, as per the Q's principle, first and first of the element which is entered first will be stored first, okay. So, first and first out. So, 10 is element which is going into my list first and it should be the first element to come outside, okay. That is the meaning of it. Now, to print DQ and to perform DQing on this particular, from where the DQing happened, the point at which NQ occurred is happening at the end and DQ should happen from front, okay. So, we have two pointers, front and rear. Insertion will be done, that is NQing will be done at rear pointer and insertion will be done at front point, deletion will be done at front pointer, okay. Now, while let us have a counter, object dot count is not equal to 0, until object dot count is not equal to 0, what we are going to do is, we are going to DQ that particular element, okay. So, console dot write line will be DQing. So, object dot DQ, this line will DQ the elements, okay. So, once it is DQing here, the DQ element should happen at, as I said at front point. What is the front point here? First element entered is 10. So, first DQed element should be 10. Again, this will go out, okay. It is not equal to 0, it will DQ 20. Not equal to 0, DQ 30. Likewise, it should produce the output, okay. So, this is just for producing the output. Therefore, I am writing insert console dot write line, okay. So, this is what output I am getting, 10, 20, 30, press any key to continue, okay. So, this is exactly reverse what we have seen in stack. In stack, I would have got the output as 30, 20, 30 when I do pop. That's the comparison between Q and stack. In stack, last and first out, the element which enters last is the first one to get removed. Whereas in Q, the element which is entered first is the element to be removed first. That's the only difference. So, it can be easily done. Whereas if I want to write my own Q and stack program, it will be lengthy. So, that is reduced in dot net, okay. This we can remove, no issue with it. So, this is how I am writing my program, okay. I feel this program is very crystal clear to understand the concepts of NQing and DQing, okay. Coming back to PPT, a presentation. So, there is a small question for you. How many ways can we initiate Q, okay. You can take a pause and give the answer, okay. I think you might have noted. The answer is three ways. Just now we have seen there are three ways to initiate a Q. One is empty, one is with some initial capacity and another is with some passing another object to it, okay. Now, various methods in Q. What are different methods in Q that are available? These are limited methods, popular methods I have taken, but these are not limited to it, okay. Clear. It will clear the complete Q. NQ, as we have seen, NQ is an element that is adds an object. DQ removes an element. Contains is to check whether a particular element is present in the list or not. Peak. Peak is similar to stack. In stack we have seen that there is a top pointer. Top always going to return the peak. This peak method is always going to return the top element, okay. So, same in Q, peak is going to return the first element. First pointer is going to return it, okay. We can even see with our program that, okay, let us see an object. We will have a console, the right line and we will let us have a peak element. What is peak element, okay, plus object dot peak. This is a method. So what it is going to return? It is going to return what let us check, okay. So peak element is what? It is peak element is 10. So as and elements are inserted, this is the first element, right. So as I said, peak is always going to return the first pointer. So even if I put here 50, so 50 is inserted first, 20 then 30. If I execute peak element should be 50. So mostly in some technical objective questions, they will ask such questions what peak is going to return in Q in dot net. So peak is always going to return the first, wherever is a first pointer. 50 is your first pointer and 30 is your rare pointer that you have to remember, okay. So we have seen all these things. Just a recall, we have written it and we have answered it, okay. Methods in Q, these are all the methods and these are some of the references which I have used. You can go through it. So it is basically very easy working with C sharp. This program, you can have multiple any other elements like for example, if I do object dot we can see all the list of elements, list of methods over here that all methods are there, you can use one by one methods into it, okay. So it's based upon the need and problem statement, okay. So you can go through it and even description about each and every method is given to it. Trim to size will what it will do, it will reduce the size. If suppose I have given the size as 20, it will reduce to that particular slot, okay.