# Implementing stacks and queues in Prolog - Depth-first and Breadth-first search

**URL:** <https://swi-prolog.discourse.group/t/implementing-stacks-and-queues-in-prolog-depth-first-and-breadth-first-search/7389>\
**Category:** Discussion\
**Created:** [April 20, 2024, 3:26pm UTC](https://swi-prolog.discourse.group/t/implementing-stacks-and-queues-in-prolog-depth-first-and-breadth-first-search/7389 "2024-04-20T15:26:20Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![joeblog](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/joeblog/32/122_2.png) [@joeblog](https://swi-prolog.discourse.group/u/joeblog)\
**Post date:** [April 23, 2024, 6:43am UTC](https://swi-prolog.discourse.group/t/implementing-stacks-and-queues-in-prolog-depth-first-and-breadth-first-search/7389/24 "2024-04-23T06:43:08Z")

</div>

I’m a bit rusty on this stuff, but recall experimenting and the automagical way SWI-Prolog traverses graphs isn’t the same as in the historical texts, and is completely different with tabling.

The safest way to ensure depth first or breadth first is to manage the _listied tree_ yourself. I recall doing a simple example which I put up here [Tree Breadth-First in Prolog - #18 by joeblog](https://swi-prolog.discourse.group/t/tree-breadth-first-in-prolog/1541/18)

---

_[View the full topic](https://swi-prolog.discourse.group/t/implementing-stacks-and-queues-in-prolog-depth-first-and-breadth-first-search/7389)._
