问题
Go channels by default behave like a queue as far as I can tell, first in first out. Is there any way to change them to work last in first out?
Basically I am doing a search and want to do DFS instead of BFS for memory constraints.
回答1:
No, this is not possible - channels are always FIFO. You could use package container/heap.
来源:https://stackoverflow.com/questions/17755222/is-there-any-way-to-make-gos-channels-behave-like-a-stack