Is there any way to make Go's channels behave like a stack

跟風遠走 提交于 2019-12-19 09:27:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!