简体   繁体   English

数据结构实现代码理解

[英]Data structures implementation code understanding

Im taking a course in algorithms and data structers, and my instructor wants me to implement several data structers (such as BST, stack etc.), and algorithms (such as quick search, DFS, etc.). 我正在学习算法和数据构造函数的课程,我的讲师希望我实现几个数据构造函数(例如BST,堆栈等)和算法(例如快速搜索,DFS等)。 I want to belive that I understand the basics, but everytime Im starting to plan the code I have the same difficulty: 我想知道我的基本知识,但是每次我开始计划代码时,我都会遇到同样的困难:

here's my current assigment: my instructor wants me to implement a DFS (depth first search) for a directed graph (using c++). 这是我目前的工作:我的老师希望我为有向图 (使用c ++) 实现DFS(深度优先搜索 )。

my question is- how do I suppose to implement the graph? 我的问题是-我应该如何实现图形? should I use adjacency matrix? 我应该使用邻接矩阵吗? or should I use adjacency list? 还是应该使用邻接表? neither this nor that?? 既不是这个也不是那个? so I asked my instructor, and his answare was this: "think of the graph as a black box "... more confused than before, I rashed to stackoverflow , and here i am posting this question... I dont look for someone to tell me how to implement DFS (or any other algorithm- I can google too!)- I just need someone to explain what should I get as input, and what should I provide as output? 所以我问我的教练,他的回答是:“把图当成黑匣子 ”……比以前更加困惑,我急着走向stackoverflow ,我在这里发布这个问题……我不找人告诉我如何实现DFS(或其他任何算法,我也可以用谷歌搜索!)-我只需要有人解释我应该作为输入获得什么,以及我应该作为输出提供什么?

I'll appreciate any comment! 我将不胜感激! thanks! 谢谢!

What he means by a black box is just that you cannot see the nodes and how they connect before you do your DFS. 他用黑匣子表示的意思是,在执行DFS之前,您无法看到节点及其连接方式。 You will probably just get the root node and your algorithm with have to explore from there. 您可能只会得到根节点,并且必须从那里进行探索。 As for what you should output- that depends on the assignment. 至于您应该输出的内容,则取决于作业。 Are you looking for specific data? 您在寻找特定数据吗? if not, perhaps a detail of which nodes were visited in which order. 如果不是,则可能详细说明按哪个顺序访问了哪些节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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