March 2019
Intermediate to advanced
336 pages
9h 9m
English
Now, let's look at the heap interface methods that are implemented by the Stack class. The new method initializes the references array, and the Push and Pop heap interface methods take the reference parameter to push and pop reference out of the stack. This is shown in the following code:
// New method of Stack Classfunc (stack *Stack) New() { stack.references = make([]*ReferenceCounter,0)}// Push methodfunc (stack *Stack) Push(reference *ReferenceCounter) { stack.references = append(stack.references[:stack.Count], reference) stack.Count = stack.Count + 1}// Pop methodfunc (stack *Stack) Pop() *ReferenceCounter { if stack.Count == 0 { return nil }var length int = len(stack.references)var reference *ReferenceCounter ...Read now
Unlock full access