6
6tc1
Hi all, I'm doing something similar to a graph traversal. And in this
instance this graph type structure could have cycles. I want to ensure
I don't revisit old nodes and was wondering if anyone could think of an
efficient way to store nodes/locations/names that have already been
visited.
I was thinking about using a Vector - but that would be very
inefficient as the number of nodes/locations/names got to the
thousands.
Should I just use a Hashtable and then use an empty string or something
for the value. In other words - if the following were the list of
locations/nodes I've visited:
"a"
"b"
"cd"
"dg"
"de"
"d"
then would it make sense to do the following:
Hashtable hashtable = new Hashtable();
hashtable.put("a", "");
hashtable.put("b", "");
and so on?
Then when I want to determine whether I've already visited the node
named "b", I would just say:
if (hashtable.get("b") != null){
}
Thanks,
Novice
instance this graph type structure could have cycles. I want to ensure
I don't revisit old nodes and was wondering if anyone could think of an
efficient way to store nodes/locations/names that have already been
visited.
I was thinking about using a Vector - but that would be very
inefficient as the number of nodes/locations/names got to the
thousands.
Should I just use a Hashtable and then use an empty string or something
for the value. In other words - if the following were the list of
locations/nodes I've visited:
"a"
"b"
"cd"
"dg"
"de"
"d"
then would it make sense to do the following:
Hashtable hashtable = new Hashtable();
hashtable.put("a", "");
hashtable.put("b", "");
and so on?
Then when I want to determine whether I've already visited the node
named "b", I would just say:
if (hashtable.get("b") != null){
}
Thanks,
Novice