March 2019
Intermediate to advanced
336 pages
9h 9m
English
In the following code section, the main method creates a stack, calls the New method, and pushes the elements after initializing them. The popped-out element value and the order is printed:
// main methodfunc main() { var stack *Stack = & Stack{} stack.New() var element1 *Element = &Element{3} var element2 *Element = &Element{5} var element3 *Element = &Element{7} var element4 *Element = &Element{9} stack.Push(element1) stack.Push(element2) stack.Push(element3) stack.Push(element4) fmt.Println(stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop())}
Run the following commands to execute the stack.go file:
go run stack.go
After executing the preceding command, we get the following output:
Read now
Unlock full access