Home Technology Subscribe to RSS

What Do You Know About Stack Implementation?

Answer Question

1 Answer - Sort by: Date | Rating

    Stack is a last in first out data structure, it means the record/data entered in the stack last, is first to be removed. There are two most common ways to implement it as:
    1. Based on arrays.
    2. Based on linked lists

    The array based technique of implementing the stack is simple and easy to use. In this case all the elements of stack are stored as array elements. As there should be structure where only last entered data is available to remove, we impose some modifications to array.

    We also use a pointer that points to the array element entered in last.
    Thus this pointer is used to access the stack elements (that are stored actually in an array) in last in first out order. Through the use of this pointer to access the stack elements, only last element can be popped.

    Each time a new element/data is pushed to stack; this pointer is set to point to that newly entered data.And each time we pop an element from the stack; this pointer is set to point to the previous element.The second approach to implement the stack, i.e. through a linked list (a list of record connected with each other via pointer) is more efficient.
    0 0

    Raaga 

    answered 3 years ago

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International