Thanasis (sch) wrote:
> >> is it possible to write a method in Java such that it returns more than
> one
[quoted text clipped - 9 lines]
> exists an unvisited adjacent node
> 2) return the leftmost unvisited adjacent node
How about
/** Find the leftmost unvisited node adjacent to a
* given node.
* @param node The given node.
* @returns The leftmost unvisited node adjacent
* to <code>node</code>, or <code>null</code>
* if no such node exists.
*/
Node leftmostUnvisitedAdjacent(Node node) { ... }
? Unless the graph can legitimately contain `null' nodes,
this seems a natural approach.

Signature
Eric.Sosman@sun.com
Wiseguy - 25 Feb 2005 18:54 GMT
Eric Sosman <eric.sosman@sun.com> scribbled on the stall wall:
> How about
>
[quoted text clipped - 9 lines]
> ? Unless the graph can legitimately contain `null' nodes,
> this seems a natural approach.
I agree. With the purpose he outlines he doesn't really need two return
values. Either your way, or having the method throw an exception for
(no nodes found) would be more intuitive than a boolean status returned.
Paul van Rossem - 25 Feb 2005 19:48 GMT
> Eric Sosman <eric.sosman@sun.com> scribbled on the stall wall:
>
[quoted text clipped - 19 lines]
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Of course. If you think about it, what would the node parameter return
if the boolean returned false??? So there is clearly no reason to return
two parameters.
Paul.
Thanasis \(sch\) - 26 Feb 2005 00:03 GMT
> How about
> /** Find the leftmost unvisited node adjacent to a
> * given node.
[quoted text clipped - 7 lines]
> ? Unless the graph can legitimately contain `null' nodes,
> this seems a natural approach.
hi eric,
thanks again for reply.
i had already found solution using 2 methods.
One that finds out if an adjacent unvisited node exists and a second one
that actually returns the leftmost adjacent unvisited node.
I think your solution does work.
regards
thanasis
Patricia Shanahan - 26 Feb 2005 00:25 GMT
Thanasis (sch) wrote:
> > How about
>
[quoted text clipped - 20 lines]
> regards
> thanasis
You do need to decide what the leftmost adjacent unvisited
node method does when there is no such node. If there is a
separate check method, the balance may shift in favor of
treating it as an exception.
Incidentally, there is another pattern that might be
appropriate, depending on the wider context. Have you
considered giving your structure the ability to return an
iterator that visits the nodes in leftmost order? The
java.util source code contains several implementation examples.
Patricia
> >> is it possible to write a method in Java such that it returns more than
>one
[quoted text clipped - 8 lines]
>exists an unvisited adjacent node
>2) return the leftmost unvisited adjacent node
Return null if it doesn't exist and the leftmost node if it does?
--
now with more cowbell