Coders Packet

Array implemention of stack using C++ programming

By Srivenurajulu G

  • arr.cpp
  • Source code Array implementation of stack.docx
  • Array implementation of stack.txt
  • A stack data structure is implemented using 1-dimensional array. Take array of specific size and insert,delete,isempty&display values into array by using LIFO principle with 'top'. Using C++


    A stack data structure can be implemented using a one-dimensional array. But stack implemented using array stores only a fixed number of data values. ... Just define a 1-dimensional array of specific size and insert or delete the values into that array by using. Last In First Out principle with the help of a variable called 'top'.


                Creating a Stack

    1. Start
    2. An array of fixed size is used to implement a stack
    3. Initially the top of the stack is made to store the value -1
    4. Stop


    Pushing data into the stack

    1. Start
    2. Read the data to be pushed into the stack
    3. Push the read value into the stack by incrementing the top of the stack as initially the stack top has -1 and top should not hold a negative value.
    4. Thus the data is pushed into the stack
    5. Stop


    Popping the data out from the stack

    1. Start
    2. Check if the top has the value -1  if yes print that the stack is empty
    3. Otherwise, print the top of the stack element until the top becomes equal to -1
    4. Stop


    Is empty

    1. Start
    2. If top is -1 then return 1 otherwise return 0
    3. Stop


    Let Us Do A Example:

      We have to push 5 elements 1,2,3,4,5 into the stack

    After pushing into the stack it looks like 






    Now Let Us Pop the element '5', '4' in the stack 

    After Poping from the stack, it looks like




    Here '5', '4' get popped out from the stack.

    Let Us Do IS EMPTY function

    Condition If Top is -1 then return 1 else return 0 (ie)return nothing

    Now After doing Isempty we have the stack look like



    At Last, We have the elements in the stack as

    1 2 3.




    Download Complete Code


    No comments yet