![]() push(N) :- It assign the element Nat counter index and increase its value by 1.Decrease size :- During the pop, operation check if the total number of elements in the array are less than the size of the array/the decrease factor, then create a new array of size (the current size of array multiply by increase factor) and copy the elements from the old array to a new array.Įach operation of the stack will work in the following way:.Increase size :- During the push, operation checks if an array is 3/4 (75%) full if yes, then create a new array of size (the current size of array multiply by increase factor) and copy the elements from the old array to a new array.In the context of the stack data structure, the increment and decrement of array size work in the following way: Decrease factor:- It decides when the size of the array should be decreased.Increase Factor:- Multiplication factor by which the array size is increased, for example, increase factor 2 means the size of the array is double every time it gets too full.Initial capacity:- Size of the array during its creation.For this first create the following three variables, these variables will help us to decide when the size of the array should be increased and when it should be decreased. We have to implement a dynamic array using an array object provided in java language. iterator() :- It returns the java iterator object for iterating through the elements of the stack.ĭynamic array is an array whose size automatically increased when it gets too full and, its size gets decreased when it is too empty.size() :- It return the total number of elements. ![]() isEmpty() :- It checks whether the stack is empty or not.peek() :- It returns (not remove) the element from the top of the stack.pop() :- It removes and returns the element from the top of the stack.push(N) :- It insert element N onto the top of the stack.The Stack data structure will supports the following operations: Design a Stack (LIFO) data structure using Dynamic Array.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |