-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
GreenMountainBoy schreef:
Has anyone seen any sample code for the use of a linked list program
using Generics. ?
Sure would appreciate it.
A little bit of some code of mine (runs through a DAG and prints it out
in some understandable way):
@Override
public String toString() {
StringBuilder result = new StringBuilder();
Set<BidiNode> nodesSeen = new HashSet<BidiNode>();
nodesSeen.add(root);
Queue<BidiNode> queue = newLinkedList<BidiNode>();
queue.offer(root);
while (!queue.isEmpty()) {
BidiNode current = queue.remove();
result.append(current);
if (current instanceof NonTerminalBidiNode) { // get rid of these
instanceofs! implement toString function in node!
NonTerminalBidiNode currentNonTerm =
(NonTerminalBidiNode) current;
for (Object label : currentNonTerm.getOutgoingLabels()) {
for (BidiNode child : currentNonTerm.getChildren(label)) {
if (!nodesSeen.contains(child)) {
nodesSeen.add(child);
queue.offer(child);
}
}
}
}
result.append(System.getProperty("line.separator"));
}
return result.toString();
}
HTH, H.
- --
Hendrik Marynshttp://tcl.sfs.uni-tuebingen.de/~hendrik/
==================http://aouw.org
Ask smart questions, get good answers:http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFF2XJpe+7xMGD3itQRApJzAJsGRKD6wBUaUoD3+HglFhKXuEXFRwCfb7uu
uCZydA3YHyOy8ng++n4ZG78=
=ft/S
-----END PGP SIGNATURE-----
string stored in one of the nodes... That would really be super
helpful. I appreciate your help in advance.