March 2019
Intermediate to advanced
336 pages
9h 9m
English
The Push method adds the node to the top of the stack class. In the following code sample, the Push method on the Stack class adds the element to the elements array and increases the Count element, while the append method adds the element to the elements of the stack class:
// Push adds a node to the stack.func (stack *Stack) Push(element *Element) { stack.elements = append(stack.elements[:stack.elementCount], element) stack.elementCount = stack.elementCount + 1}
The example output after the push method is invoked with parameter elements as follows. The element with the value 7 is pushed to the stack. The count of the elements before pushing to the stack is 2, and, after pushing to the stack, this figure is 3:
Let's take ...
Read now
Unlock full access