C++ | Rust | Python | Go | |
---|---|---|---|---|
Declaration |
|
|
|
Go doesn't have a built-in stack data structure like C++ stack in Go is implemented using a slice.
|
Empty |
|
|
|
Method Reciever (s *Stack) (s *Stack) before the function name is a method receiver. This associates the function to Stack type & allows the method to access/modify the Stack member variables. Similar to how you we define method in class in C++ or Java
|
Last |
|
|
|
|
Pop |
|
|
|
if array size>0, store 1 less element from back
|
push |
|
|
|
Push element at end of slice and store back into vals
|
Top |
|
|
|
|