![]() Hence no work is associated in creating new memory space when the size of stack increases and garbage collecting it when the size of the stack decreases. Advantages of stack using array :Īrrays are more efficient in terms of time and memory as it does not involve using pointers like in case of linked list. Space complexity = O(N), where N = number of elements. We do not iterate over the array elements for performing any of these operations. Top most element of the stack = 4 Time and space complexities of stack implementation using array :Īll operations push(), pop(), peek(), isEmpty(), isFull(), getSize() require constant time. method to get the current size of stack ("Top most element of the stack = " + stackArray) method to peek/view the topmost element of the stack ("Element popped from the stack = " + elementPopped) method to pop the top element from the stack ("Element pushed to the stack = " + stackArray) Cannot insert new element " + element + " to the stack") method to push a new element to the stack initialize top and current size of stack top of stack and current size of the stack
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |