简体   繁体   中英

Implementing depth-first-search in C++

I'm learning about data structures and abstract data types, and I keep getting stuck on one question that keeps coming up.

I don't understand how computer science can be 50 years old now (or older, I don't know exactly) and how data structures, ADTs, and algorithms can be such a foundational part of it all, yet still there is no standard to any of it.

My question is actually pretty specific: I'm trying to implement depth-first-search in C++ in a way that can work on any native (built-in) data-type. My question is, where do I look first? I know the stack class from the STL can be used to implement the DFS algorithm, but is the STL the first place to look? Should I be implementing DFS from scratch, using a stack and what I know about implementing this algorithm? Or do professional programmers have a library they turn to when they need to pursue this kind of search?

Please advise, this question isn't as concrete as I'd like it to be.

Boost has a C++ depth first search implementation here:

http://www.boost.org/doc/libs/1_42_0/libs/graph/doc/depth_first_search.html

Put your knowledge to use! You know STL and you know how to implement DFS using stack, and most importantly, it is quite simple, so you can code it yourself.

Most people suggest Boost. But if this is the only thing you would need Boost for, then it is better to write DFS on your own. On the other hand, you also want to learn how to use what is already available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM