![]() ![]() Use array when you want fixed size Stack and linked list for dynamic size.We can implement stack using an array or a linked list.We call insert operation as Push and delete operation as Pop in Stack.The last element inserted is popped out first. The stack is based on LIFO (last in first out).Now, you know how important the Stack is, here is a quick summary of all the above points. Here are some common application of Stack data structures. Applications of Stack Data StructureĪs we already see that insertion and deletion take constant time which is performance efficient. If top pointer refers to null then the Stack is already empty. We only need to check the underflow condition here. PUSH and POP operations in the linked list take O(1) constant time because a pointer is at the end of the linked list which manage insertion and deletion. Here are some quick facts about Stack using linked lists which will be helpful to make a decision. ![]() It is convenient to use a linked list in place of an array when the number of elements is unknown. They have dynamic length, it means there is no limit on the number of elements we can add. Linked List Representation of Stackīefore moving to this part you must know about linked list and the difference between array and linked list.Ī linked list has some advantages and disadvantages over an array which make it more suitable for some specific tasks. It is necessary to implement methods to check overflow and underflow condition because it is a common error. You can create a class in any language and implement these methods. This is the pseudo code to create stack using an array. Print("Stack Underflow, No more elements left") Print("Stack Over flow, No more space left") Here is the pseudo code for Stack using array arr of size n. It can be very helpful to check overflow and underflow condition. When the topPointer = -1, it means the stack is empty and when the topPointer = n it means the stack is full.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |