![]() ![]() Let's understand the stack memory through an example. When any function is called then it occupies some space in the memory known as a stack memory. The third segment, i.e., stack is used to store all the function calls and the local variables. The global variables are the variables which are declared outside the function and the lifetime is throughout the program. Another segment of the memory stores the global or the static variables. One segment of the memory stores the instructions which are to be executed. The memory which is assigned to the program or application in a typical architecture is divided into four segments. It is very crucial to know that how system manages the memory and accessible to us as programmers. Here, we will see the architecture of memory. In the last level, all the nodes are far as left as possible. It is a complete binary tree that satisfies the condition of the heap property where complete binary tree is a tree in which all the levels are completely filled except the last level. ![]() Heap data structure can be implemented either using arrays or trees. By default, all the global variables are stored in the heap memory. Heap is also a data structure or memory used to store the global variables. If we perform pop operation, then the topmost element, i.e., 1 would be removed from the stack as shown below: What is Heap? Since element 1 comes above the element 2, so element 1 would be considered the top of the stack. If we want to insert 1 element in the stack, then the stack would like: Since there is only one element in the stack, so 2 element would be at the top of the stack. After push operation, the stack would look like: Suppose we want to insert 2 element in the stack. Now we will perform push and pop operations on the stack. The above representation is an empty stack and let's assume that stack is 's'. It can be represented logically as a three-sided figure as a container open from one side. We can observe in the above figure that stack looks like a container which is opened from one side. Pop(): It removes the most recent element from the stack. Pop: The process of deleting an element from the stack is known as a pop operation. ![]() Push(x): It inserts an element x into the stack.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |