March 2020
Intermediate to advanced
406 pages
8h 39m
English
A stack serves the grouping of data using push and pop to add and remove elements from the container. Stacks usually have a LIFO (short for last in first out) order of operation, and the Peek operation usually lets you see what is on top of the stack without removing it from the stack. Stacks are very handy for things that have a bounded set of memory, as they can utilize the allocated memory effectively. The following code is a simple implementation of a stack:
package mainimport ( "fmt" stack "github.com/golang-collections/collections/stack")func main() { // Create a new stack fmt.Println("Creating New Stack") exstack := stack.New() fmt.Println("Pushing 1 to stack") exstack.Push(1) // push 1 to stack fmt.Println("Top of Stack is : ...Read now
Unlock full access