Re: Depth First Search in Binary Search Tree?
- From: "howa" <howachen@xxxxxxxxx>
- Date: 26 Oct 2006 08:40:05 -0700
Howard 寫道:
"howa" <howachen@xxxxxxxxx> wrote in message
news:1161876654.310945.67020@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
from the web, i found:
void dfs (TreeElement t) {
print(t);
if (t.left!=null) dfs(t.left);
if (t.right!=null) dfs(t.right);
}
seems same as pre-order?
It IS a pre-order traversal. It's not a search at all. Why it's called
"dfs" is beyond me. A search implies you're looking for something, right?
There's nothing in that code which checks to see if a desired node is found,
nor any way to report it if it were found. It's simply a poorly named
pre-order traversal.
-Howard
if this is a binary tree, there is no need to check `visited` or not
.
- Follow-Ups:
- Re: Depth First Search in Binary Search Tree?
- From: Howard
- Re: Depth First Search in Binary Search Tree?
- References:
- Depth First Search in Binary Search Tree?
- From: howa
- Re: Depth First Search in Binary Search Tree?
- From: Howard
- Re: Depth First Search in Binary Search Tree?
- From: howa
- Re: Depth First Search in Binary Search Tree?
- From: Howard
- Depth First Search in Binary Search Tree?
- Prev by Date: Re: Depth First Search in Binary Search Tree?
- Next by Date: Re: Portable use of timers
- Previous by thread: Re: Depth First Search in Binary Search Tree?
- Next by thread: Re: Depth First Search in Binary Search Tree?
- Index(es):
Relevant Pages
|
|