Stack Go or Golang



Stack Go or Golang

Stack Go or Golang

Stack implementation using Go or Golang (https://github.com/SivaprasadTamatam/DS-Algo/tree/master/Stack)
The operations that can be performed on a stack are:

Push: This operation adds an element to the top of the stack.
Pop: This operation removes the top element from the stack.
Peek or Top: This operation returns the top element from the stack without removing it.
isEmpty: This operation checks if the stack is empty.
Size: This operation returns the number of elements in the stack.

The time complexity for each of these operations in a stack implemented using an array or a linked list is as follows:

Push: O(1) – This operation adds an element to the top of the stack in constant time since we simply add the element to the end of the array or the head of the linked list.
Pop: O(1) – This operation removes the top element from the stack in constant time since we simply remove the last element of the array or the head of the linked list.
Peek or Top: O(1) – This operation returns the top element from the stack without removing it in constant time since we simply return the last element of the array or the head of the linked list.
isEmpty: O(1) – This operation checks if the stack is empty in constant time by simply checking if the size of the stack is zero.
Size: O(1) – This operation returns the number of elements in the stack in constant time since we can simply return the size of the array or the linked list.