A stack is a linear data structure in which all the insertion and deletion of data are done at one end only. Stacks can be implemented by using other data structures like, array and linked lists.

The Stack is widely used in many applications of internal compute processing. One of the widely but least known applications is of having it being used in converting and evaluating Polish notation expressions.

    • Infix
    • Prefix
    • Postfix

Comparative to arrays and linked lists, which allows us to insert and delete values from any place. The stack is a linear data structure, and all the insertion and deletion of its values are done at the same end which is called the top of the stack.You can imagine the stack of plates and pile of books to understand the stack better. As the item in this form of data structure can be removed or added from the top only, it establishes the property that the last item to be added will be the first item to be removed.so you can say that the stack follows the Last In First Out (LIFO) structure.

Stack Data Structure

Pseudo code  of  Insertion in Stack(PUSH)
Step 1: Insertion(a,top,item,max)
Step 2:  If top = max then
            Print ‘STACK Overflow’
            top = top + 1
         End if
         A[top]= Item
Sample implementation of Stack in Golang.

package main
import "fmt"
type Stack struct { //stack
   values []int 
   top    int
func NewStack() *Stack {
   return & Stack{
      values: make([]int, 0),
      top:    -1,
// Push adds a value to the top of the stack.
func (st *Stack) Push(value int) {
   st.values = append(st.values, value)
// Pop removes and returns the top value from the stack.
func (st *Stack) Pop() int {
   if st.IsEmpty() {
      return 0
   value := st.values[st.top]
   return value
func (st *Stack) IsEmpty() bool {
   return st.top == -1
func main() {
   st := NewStack()
   fmt.Println("The value popped from the stack is given as:")
   fmt.Println("Is the stack empty?")