Implementation of a stack is possible using either arrays or linked lists. The following is a simple array implementation of the stack data structure with its most common operations.
```C++
//Stack implementation using array in C++
//You can also include<stack> and then use the C++ STL Library stack class.
#include <bits/stdc++.h>
using namespace std;
class Stack {
int t;
int arr[MaxN];
public:
Stack() {
t = 0;
}
int size() {
return t;
}
bool isEmpty() {
return t <1;
}
int top() {
return arr[t];
}
void push(int x) {
if (++t >= MaxN) {
cout << "Stack is full" << '\n';
return;
}
arr[t] = x;
}
void pop() {
arr[t--] = 0;
}
};
int main() {
Stack st;
st.push(4);
st.push(3);
st.push(5);
while (!st.isEmpty()) {
cout <<st.size()<<''<<st.top()<<'\n';
st.pop();
}
return 0;
}
```
#### Using Arrays as Stacks
In some programming languages an array has stack functionality, allowing the developer to perform **push** and **pop** operations without the need for a custom stack data structure.
For example, an array in JavaScript has **push** and **pop** methods allowing one to easily implement stack functionality in an application.
```js
stack = [];
let i = 0;
while(i <5)
stack.push(i++);
while(stack.length) {
stack.pop();
}
```
A List in Python can also perform stack functionality in an application. Instead of **push**, one can use the **append** method.
```python
stack = []
for i in range(5):
stack.append(i)
while len(stack):
stack.pop()
```
#### Applications
* Turn recursion into loop.
* Redo-Undo features.
* Sudoku solver
* Depth First Search.
* Tree traversals
* Infix expression -> Prefix/Postfix expression
* Valid Parentheses
#### More Information:
* [More Info on Stacks - GeeksForGeeks](http://www.geeksforgeeks.org/stack-data-structure/)