 Rudrapa Vardarikar working as an assistant professor in computer science and engineering department at Walch instead of technology, Solapur. Today, we are going to learn about the stack using STL, learning outcomes. At the end of the session, students will be able to perform different operations on stack using STL. So, as we have already seen this stack in a data structures, this stack is again one data structure which is going to hold the values. Basically, this stack adapter or any stack concept is basically worked on last in first thought manner. Now, last in first thought means what? Let us say we will have one array. In this array, they are going to insert the elements. So at that time, it starts inserting the element into the array, then when actually it comes for the deletion of any element from the array. So at that time, it is going to delete the last inserted element from the array. So that is nothing but the last in first thought. In the same example, if you will see in our operating system also, in operating system it is going to use this stack to store the information about the function calls. So let us say when we are going to call any function. So at that time, the main function is the function which is going to be called first. So now, the first of all this main function is going to be put or push into the stack. Then after that, let us say I am going to call any function, call it as an add function. So now that add function is going to be put on the top of the main because that add function has called after the main function. So let us consider that when actually execution is happening about the add function. So at that time, that add function has called one more function called insert element. So that insert element is again going to be put in a stack on the top of the add function. So in this way, we are going to put the functions or in this way, we are going to use the stack in operating systems also. So after entering the values, the enter element function is going to be closed. So now top of the stack becomes decrement and that comes to the add function. After execution of the add function, the control is come back to the main function. So in this way, to maintain the function calls, stack is going to be used. So what are the different operations we are going to perform in a stack? So by using stack, we are going to perform the push, then pop, then top and then size. These are the different functions or methods we are going to use in a stack. So let us see the program on this stack. So here whenever we are going to start for the stl using this stack, so first of all we need to include this library or the header file in our program. So we will write hash include this stack. So now we are able to use the inbuilt functions provided by this stl. So what we are going to do here? So now first of all, let us say this is the stack is my class or the template which is going to store the integer values and the reference is what? s is my reference. So now here with the help of this s object or reference, we are going to perform the different operations. So see here, so s.push of 10 means what? The first of all we are going to push the 10 into our stack. So now I want to traverse this stack, I want to show the display the elements from the stack. So at that time what we are going to do? So now for that also we have written one function called the show stack. So now the control comes to here, this show stack has one argument that is nothing but the reference of the stack. So now here we are catching that reference st and based on this st, I am going to perform the further operations. Means what? Here I am rotating over the stack. So now here, while stack.empty, we are going to retrieve the top or we are going to print the top of the stack. So whenever we are going to insert any element in our stack, so that is the first element. So after insertion of any element in the stack, we are going to increment the top. So top is the topest position which is going to return the top element from the stack. So let's see what I have done, simply we have pushed 10 into our stack. So when we will run this code, we will got the 10. So now after that, let's say I want to perform s.push of 20. So what we are expecting? Let's see here. So now here the 10 is the first element, after that 10 we have inserted the 20. So now here on the top of the stack we will have the 20 element. Okay, fine. So let's say I want to add like s.push 30. So s.push 40, fine. So these are the values we are going to add. Now we are going to add these values into the stack by using push function or push method. It has one argument called the element, whatever element we are going to pass here that is going to be store or add into your stack. So let's see the content or element of the stack, see 10, 20, 30 and 40. So now here on the top of the stack we will have the 40, okay, fine. So let's say I want to perform the pop operation. So now how we are going to perform the pop operation? Pop means what? Deleting the top element from the stack that is nothing but the pop. So what we have done? I have done s.pop here, that is a single function what we have done. So we have inserted in the sequence. So what is the top of the stack? We will have the 40 on the top of the stack. So when we will perform the pop operation it should remove that pop and we have called this show stack method or function which is going to return all the element from the stack, okay. So let's check here, see here. What we have done? These are the elements of the stack. After performing the pop operation we are getting these elements 10, 20 and 30. Now on the top of the stack we will have the 30, okay. Let's say here only I want to perform one more pop operation. So what we are expecting then? See here, two elements has been deleted from the stack that is 40 and 30, right. So now we will have the 10 and 20 in our stack. So the top of the stack has the 20 element, fine. So now even I want to print the top of the stack. I want to access the top of the stack element, okay. So let's say after this function I want to perform the s.push operation and let's say I want to insert the 30 here, okay, s.push element. I want to insert the 40 element, okay fine. So now after this insertion now I want to get the top element. So let's check here. So what it is going to be written? The top value becomes 40, right. Because after this pop operation we have inserted two more values 30 and 40. So now my top of the stack becomes this one, fine. So let's say if I am not going to perform these operations. So what we will have after these two pop operations we will have only 10 and 20 and top of the stack will have the 20, right, fine. So let's say now I want to know how many elements are there in my stack, fine. So to get the total number of elements available in my stack we need to use the s.size, right. So s.size is the function. Let's say run this one. So say see here the s.size becomes 2 because in our stack we will have only 10 and 20 and top value becomes 20. So means we will have only two elements in my stack. So the s.size of my stack becomes 2. So in this way we are going to use the stack or in this way we are going to implement the stack using the standard template libraries, okay. So now think and write, is it possible to delete any element from the stack from any position? So just pause the video and write your answer, no, right. We cannot delete any intermediate element from the stack, why? Because it's a last in first technique, right, last in first out technique means the lastly added element in a stack is going to be deleted first. That is the standard technique given by the stack. So we cannot delete any intermediate or any positions element from the stack. References object-oriented programming with C++, 6th edition by Ibar Guru Swami. Hope you got these concepts, thank you.