P
P
progerstas2020-11-14 16:05:59
go
progerstas, 2020-11-14 16:05:59

What to use?

I need a data type for the stack, it will contain elements of different types. What should I use?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uvelichitel, 2020-11-14
@progerstas

The stack is easiest to make on a singly linked list, as in the mentioned https://pkg.go.dev/github.com/golang-collections/c... But you can make a stack on an array, I was also interested and I raised the question on stackoverflow https://stackoverflow.com/questions/28541609/looki...There are fewer allocations on the array. Regarding the type of elements - in my opinion, implementations with empty interfaces are methodical and demonstrative. In production, solutions with specific types are used. The need for a stack of different types of elements suggests a raw architecture. Try to instantiate the type. At least let there be an interface of the required methods. You are going to somehow use the elements of this stack in a uniform way, which means they will need methods of use. But not an empty interface, as for me.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question