snippetgoCritical
How to implement resizable arrays in Go
Viewed 0 times
implementarraysresizablehow
Problem
I come from a C++ background and I'm used to using the
Lets assume I want a dynamic array of these:
What is the standard way of doing this?
A snippet would be very useful
std::vector class for things like this.Lets assume I want a dynamic array of these:
type a struct {
b int
c string
}What is the standard way of doing this?
A snippet would be very useful
Solution
Use the
Example:
Refer to the spec for more info on append.
append() builtinExample:
type mytype struct {
a, b int
}
func main() {
a := []mytype{mytype{1, 2}, mytype{3, 4}}
a = append(a, mytype{5, 6})
}Refer to the spec for more info on append.
Code Snippets
type mytype struct {
a, b int
}
func main() {
a := []mytype{mytype{1, 2}, mytype{3, 4}}
a = append(a, mytype{5, 6})
}Context
Stack Overflow Q#3387273, score: 108
Revisions (0)
No revisions yet.