Stack in Data Structure | Data Structure Tutorial | Mr. Srinivas

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to nourish technologies this is cinemas so in this session we are going to discuss about a stack data structure what is a stock means this is an algorithm right so nothing but this is one abstract data type or set of rules so what is the use of stack means just to store the information in some of the situations if you follow the rules of a stack so we can access the information effectively so what are the applications and where we are using stack exactly so that we will see later so first here now we will discuss so what is the stack and how to implement a stack and finally we will discuss applications of a stack okay so first one so what is a stack means a simple and algorithm that works based on a rule called last in first out we can call it as a leaf oh so based on a last in first out rule a stack works so what you inserted last into the memory that will come out first it is a simple rule so one best example where we are placing the series sadist and so we are inserting right the seed is right so then the CD will move like this and here it is this is a CD and this is a next CD and this is a third state see you inserted first second third so this is inserting so if you want to pick out one CD from the CD stand then the third one will come first it will come first so this is just deleting or collecting the information and this is inserting the information so a stack algorithm so we'll run a based on the rule last in first out right how the insertions and how the deletions right every data structure right or right every stack should have a particular amount of memory block initially so we can call it as a capacity of stack so what is the capacities and how we will decide right so either using dynamic memory allocation we can decide or we can use a static memory allocation also so first we will see a static memory allocation is nothing but a constant memory allocation so what we will use in a static memory allocation simply we are using the concept of array we are using the concept of array so how see for example how we are declaring an array means in a our are the size is a 5 5 so whenever we declare variable like this it gets a memory allocation a block to store five elements at some location suppose two zero four six two zero four eight five zero five two and five four so this is memory allocation so now I want to implement a stack and of course write a stack implementation also with the help of arrays only arrays concept just rotate this memory allocation so by minus 90 degrees minus 90 observe integer type elements we are storing write the name is a stack and of course it is array only but the approach is different stacked here it is the capacity capacity suppose initial capacity we are giving like this the same memory allocation we are writing in different ways so this is now one two three four five this is a base address to zero four six two zero four eight two zero five zero two zero five two two zero five four here base address of the block who will hold the array variable ARR holds the base address of the block to collect the information of the memory block in the same way a stack variable is an array variable is holding the base address of the block 2 0 4 6 2 0 4 6 this is what we called static memory allocation how we can allocate the memory right to a stack is a fixed memory fixed memory so for example if you want to implement a stack dynamically then we should use the concept of we should use the concept of write a malloc function Cal log function real log function and free function we already discussed the dynamic memory allocation concept in a C language right so now here it is for arrays so what are the functions we are using in a steady Li B dot H means a catalog function and next one real log function so what is the use of a catalog function we can allocate the memory dynamically of course but with a fixed size we cannot change if you want to increase or decrease the size of array or size of memory block we should go for a real log function we should go for real log function very simple how to allocate the memory observe so how to allocate the memory dynamically to stack so first we are declaring integer pointer variable but the variable name is a stack stack in a static memory allocation we are using array with of exercise but now here it is a pointer so only a stack get memory allocation at some location at some location now it is ready to accept one integer array nothing but a memory block address it is ready to hold how we are allocating the memory to this one how so that is using a catalog function so what is the size nothing but what is the capacity capacity we have to pass see for example the capacity is a 5 capacity equals to 5 capacity we are passing and next one what is the size of each element that we are going to store in the stack sizeof integer so that we are collecting what catalog function will do a capacity into sizeof integer capacity is a 5 sizeof integer is a 2 is nothing but 10 bytes memory it will allocate a block 10 bytes memory it will allocate and the base address suppose 2 0 4 6 we should collect into stacks so that it start pointing to this 1 here it is a stack we are collecting that information into variable stack but stack is of type 1 is an integer pointer type but catalog function return type is a wide pointer we know that catalog function returns wide pointer this is what we called generic pointer this is already we discussed clearly what is the prototype of a catalog function right why it is returning wide pointer how to typecast a pointer all these things already we discussed in a dynamic memory allocation con except of a C language right so once go through that how memory will be allocated using a catalog function this is just allocating a memory to this stack with a fixed size here initial capacity is a 5 so if I want to store the sixth element then what will happen then we should go for a real log function for that we have to write the logic how to write the logic and all we'll see okay so for simply this is memory allocation dynamically to the stack right so we can implement a stack data structure algorithm in two ways either by using a static memory allocation concept or by using dynamic memory allocation concept static memory allocation concept means we are using arrays dynamic memory allocation concept means we are using write the CL log function and real log function of course with the help of a pointers concept okay so this is just only creation answer what are the operations we can perform right on a stack so once a stack is ready once stack has been created so what are the operations we can perform on a stack data what are the stack operations what are the stack operations so first one first one so creation of a stack creation either dynamically or with the static memory allocation second one we can push the elements into the stack right we can push the elements right so what is that pushing the element a right nothing but insertion of elements according to that algorithm so right as some of the words a terminology we should understand but here it is whenever we are calling push function so whatever the element you want to insert that we are passing suppose a stack is an integer stack that element we should pass what element you want to push and next one third one pop third one is popper but here whenever we are calling a pop function no need to pass anything any argument so why what is the reason because right in this from the stack if you want to pop any element it is always try to access a last element right so what you insert at the element last so that will come out first the last element what is the top of the stack that will be collected that will be collected and next one fourth one Traverse function so what is a Traverse function just displaying all the elements of the stack displaying all the elements of the stack is nothing but Traverse function so these are the main functions we are using in the implementation of a stack so some more functions these are optional and anyway we are implementing at the time of a stack implementation is empty or not if stack is empty or it contains elements or not and next one sixth one is full or not is full and next sixth one sohow seventh one how many elements are there so what is the length of the stack I think but simply we can call it as a size also more clearly so what is the size of the stack how many elements are present how many elements are present in the stack so these many things so we are implementing these many types right so implementation of all these functions just writing logic for all these functions is nothing but a stack implementation once you implement all these things then a stack is ready with the help of that stack then we can store the information effectively into every program into every programming application so that we can process the information effectively so first for example so we are creating the stack with a size 5 we are creating the stack creating either if you want to push the elements or if you want to pop the elements that is possible only from the top of the stack any operation you can perform with the help of element top element only from the top only either we are inserting or deleting the elements nothing but we will push or we will pop so first of all for example here so we are calling push of element 10 so then the stack will be like this right it will go like this from the top it will stay here and next if you want to push 20 20 then this is the stack 10 next element here 20 and remaining nothing and next for example here so we just want to pop pop means so which element will be popular the last in first out is a 20 will be deleted so then in the stack only 10 will be present 20 will pop willpower next for example here it is we are pushing 30 just push 40 push 50 50 then a stack will be like this 10 30 40 50 and next for example if you want to perform a pop operation so then then here it is at ten thirty forty here it is fifty will come out it will pop so what you inserted last so that will come out first so if you insert a five elements we cannot insert the sixth element right in a static memory allocation of course in a dynamic memory allocations we will increase with the help of real log function and we are inserting anyway so these are just operations on a stack how we are inserting the elements how we are deleting the elements just we are performing push operations and pop operations all these operations we can perform with the help of a variable called top because we should perform all the operations on the stack from the top only either you want to push or you want to pop the elements okay so implementation how to write the logic of all these things all these functions right so we will see in the next session right so for more videos so please log in to nourish idea channel thank you
Info
Channel: Naresh i Technologies
Views: 666,260
Rating: 4.8799076 out of 5
Keywords: Srinivas, Naresh IT, Hands on Data Structures Training, Data Structures Demo, Online Data Structures Training, Data Structures Tutorial Videos, Data Structures Overview, Data Structures Interview Questions, Stack Data Structure, Stack, Stacks and Queues, stack data structure in c, example of a stack, example of a stack data structure, practical example of stack data structure, Structure, data, Stack Data Structure Tutorial, stack in ds, ds stack, stack examples
Id: BrVZZZkkGGI
Channel Id: undefined
Length: 16min 1sec (961 seconds)
Published: Fri Sep 23 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.