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++

**Definition:**

**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'.**

**Algorithm:**

** ****Creating a Stack**

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

**Pushing data into the stack**

- Start
- Read the data to be pushed into the stack
- 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.
- Thus the data is pushed into the stack
- Stop

**Popping the data out from the stack**

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

**Is empty**

- Start
- If top is -1 then return 1 otherwise return 0
- 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**

**5**

**4**

**3**

**2**

**1**

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

After **Poping from the stack, it looks like**

**3**

**2**

**1 **

**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**

**3**

**2**

**1 **

**At Last, We have the elements in the stack as**

**1 2 3.**

Submitted by Srivenurajulu G (Srivenurajulu)

Download packets of source code on Coders Packet

## Comments