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
Pushing data into the stack
Popping the data out from the stack
Is empty
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