traversal

C# graph traversal - tracking path between any two nodes

Looking for a good approach to keep track of a Breadth-First traversal between two nodes, without knowing anything about the graph. Versus Depth-First (where you can throw away the path if it doesn't pan out) you may have quite a few "open" possibilities during the traversal. ...

How do you iterate backwards through an STL list ?

I'm writing some cross-platform code between Windows and Mac. If list::end() "returns an iterator that addresses the location succeeding the last element in a list" and can be checked when traversing a list forward, what is the best way to traverse backwards? This code workson the Mac but not on Windows (can't decrement beyond first e...

C++ Recursive Traversals with Function Pointers

template <class T> void BT<T>::inOrder(void (*inOrderPtr)(T&)) { inOrderPtr(inOrder(this->root)); } template <class T> void BT<T>::inOrder(Node<T>* root) const { if (root->left != NULL) inOrder(root->left); //something here if (root->right != NULL) inOrder(root->right); } Ok I am trying to create t...

Traversing a unidirectional tree efficiently

Hey folks, I've got a unidirectional tree of objects, in which each objects points to its parent. Given an object, I need to obtain its entire subtree of descendants, as a collection of objects. The objects are not actually in any data structure, but I can easily get a collection of all the objects. The naive approach is to examine eac...

unique path in a directed graph

Hi, I'm designing an algorithm for class that will determine if a graph is unique with respect to a vertex v such that for any u <> v there is at most one path from v to u. I've started by using BFS to find the shortest path from v to another vertex u, and then running BFS again to see if an alternate path can be found from v to u. I th...

About Trees and Prefix (Polish) Notation?

My MIPS Assembly class required me to read in an expression of unknown size into a Parse Tree. I've never had to deal with trees, so this is how I went around storing values: Lets say the user entered the expression 1 + 3 - 4 (each operand could only be a digit 1-9) My leftmost child node would be the starting point and contain 2 piec...

Traversing 9 levels up in jQuery

Hi, A click event occurs on a href tag, and I need to reference the class of a that is 9 levels up, so: <div class="blah" id="234"> <div> <div> <div> <div> <div> <div><a href=""></a> The only way I know is to call parent() 9 times, what else can I do? ...

C# Graph Traversal

This algorithm does a great job of traversing the nodes in a graph. Dictionary<Node, bool> visited = new Dictionary<Node, bool>(); Queue<Node> worklist = new Queue<Node>(); visited.Add(this, false); worklist.Enqueue(this); while (worklist.Count != 0) { Node node = worklist.Dequeue(); foreach (Node neighbor in node.Neighbors...

Infinite loop while traversing XML in Actionscript 3

Hello, I've narrowed down the code to this (ignore the colourization): var theXML:XML = <xml> word </xml>; for each (var i:XML in theXML.*) { trace(i); } For some reason, this prints out "word" over and over indefinitely. Any thoughts as to why? I'm a bit out of practice and have a feeling it's something obvious...

Hierarchy traversal and comparison modules for Python?

I deal with a lot of hierarchies in my day to day development. File systems, nested DAG nodes in Autodesk Maya, etc. I'm wondering, are there any good modules for Python specifically designed to traverse and compare hierarchies of objects? Of particular interest would be ways to do 'fuzzy' comparisons between two nearly identical hier...

How to get nodes lying inside a range with javascript?

I'm trying to get all the DOM nodes that are within a range object, what's the best way to do this? var selection = window.getSelection(); //what the user has selected var range = selection.getRangeAt(0); //the first range of the selection var startNode = range.startContainer; var endNode = range.endContainer; var allNodes = /*insert ma...

HTML Traverse and Find Best Practices

Hey I was thinking about making some crawlers so that I can get an URL and traverse through the html and just get certain things I might need/want. I was thinking about using Php + xPath but I'm not sure that might be the best way. What do you guys think? Are there any best practices, recommendations, or anything else? ...

Fastest way to access a node

I have about thousand DIV tags structured this way: <div id="1"> <div class="1"></div> <div class="2"></div> ... </div> <div id="2"> <div class="1"></div> <div class="2"></div> ... </div> If I want to now access a particular node, say 'div#10 div.5' - what is the fastest way to do it using javascript DOM trave...

Graph navigation with C#

I having a bit of a quandry trying to come up with a good algorithm to navigate the following graph. If a user chooses "Table 21" as a starting point, I need to be able to get the path to any other table from that starting table. EX: If the user chooses "Table 21" as a start and then adds a value from "Table 8", I need to create the ...

JQuery Find with string variables

Can I query the DOM with $() using a string variable as a parameter? i.e. var divContainerID = "divBlock1"; $(divContainerID).show(); ...

How to traverse keys of a Hashtable in alphabetical order?

What is the easiest way to traverse a hashtable's keys in ascending alphabetical order? ...

Filter the jQuery object with a plugin

I'm trying to build a jQuery plugin that filters the provided jQuery object to only return some elements similar to the .filter(expr) function. This is more for educationg myself then for a real world problem. However I can't figure out how to remove elements from the provided jQuery object (or only return certain others, doesn't really ...

NAT Traversal with Java

I'm trying to find a way to communicate between two NAT-ed nodes using Java. My requirements pretty much align with the ICE-specification; i.e. I want to try STUN first and then fall back to relaying the data when nothing else works. I need some kind of streaming protocol, so either TCP must be supported or the library should provide som...

NHibernate Traversal Question - Creating a Fluent Interface

I'm stumped with NHibernate and my Domain Model right now. I'm imagining a nice API in my head but I'm having a really hard time making it a reality. Here's an example of what I'm trying to accomplish: Trip trip = new Trip("Austria2009"); foreach(User user in trip.People.Crew.IsApproved()) { reponse.write(user.Firstname); } // Or ...

NHibernate Aggregate Traversal (C#)

My application has a very simple model right now and I'm trying to find the best way to traverse through an aggregate. As you can see in my model diagram at the bottom, I have an account, a trip and a list of people attending a trip. I would like to be able to view all of the trips an account is apart of and I have come up with something...