traversal

Getting a modified preorder tree traversal model (nested set) into a <ul>

断了今生、忘了曾经 提交于 2019-11-26 18:22:17
I am trying to get my data which is hierarchically set up with a tree traversal model into an < ul> in order to show on my site. Here is my code: function getCats($) { // retrieve all children of $parent $query = "SELECT max(rght) as max from t_categories"; $row = C_DB::fetchSingleRow($query); $max = $row["max"]; $result ="<ul>"; $query = "SELECT * from t_categories where lft >=0 and rght <= $max"; if($rs = C_DB::fetchRecordset($query)){ $p_right =""; $p_left =""; $p_diff=""; while($row = C_DB::fetchRow($rs)){ $diff = $row["rght"] -$row["lft"]; if($diff == $p_diff){ $result.= "<li>".$row[

Traverse a XML using Recursive function

人走茶凉 提交于 2019-11-26 16:29:45
问题 How can I traverse (read all the nodes in order) a XML document using recursive functions in c#? What I want is to read all the nodes in xml (which has attributes) and print them in the same structure as xml (but without Node Localname) Thanks 回答1: using System.Xml; namespace ConsoleApplication1 { class Program { static void Main( string[] args ) { var doc = new XmlDocument(); // Load xml document. TraverseNodes( doc.ChildNodes ); } private static void TraverseNodes( XmlNodeList nodes ) {

How to select all content between two tags in jQuery

ぐ巨炮叔叔 提交于 2019-11-26 16:07:35
I have a document with headings and unordered lists. How can I use JQuery to select a given heading (by its unique class name) AND all content between that heading and the next heading? Update: Your suggestions are great, but aren't what I'm looking for. In the below code, for example, I would like to access only the "h1" with id of "heading2" and everything up to, but not including the "h1" with id of "heading3". The jQuery examples provided above will access everyting after the first "h" tag that is not an "h" tag. ... or, correct me if I'm wrong :) <h1 id="heading1">...</h1> <ul>...</ul> <p

An example of a Foldable which is not a Functor (or not Traversable)?

我只是一个虾纸丫 提交于 2019-11-26 15:44:38
问题 A Foldable instance is likely to be some sort of container, and so is likely to be a Functor as well. Indeed, this says A Foldable type is also a container (although the class does not technically require Functor , interesting Foldable s are all Functor s). So is there an example of a Foldable which is not naturally a Functor or a Traversable ? (which perhaps the Haskell wiki page missed :-) ) 回答1: Here's a fully parametric example: data Weird a = Weird a (a -> a) instance Foldable Weird

Traverse Matrix in Diagonal strips

青春壹個敷衍的年華 提交于 2019-11-26 12:21:00
问题 I thought this problem had a trivial solution, couple of for loops and some fancy counters, but apparently it is rather more complicated. So my question is, how would you write (in C) a function traversal of a square matrix in diagonal strips. Example: 1 2 3 4 5 6 7 8 9 Would have to be traversed in the following order: [1],[2,4],[3,5,7],[6,8],[9] Each strip above is enclosed by square brackets. One of the requirements is being able to distinguish between strips. Meaning that you know when

jquery find closest previous sibling with class

前提是你 提交于 2019-11-26 12:12:15
here's the rough html I get to work with: <li class="par_cat"></li> <li class="sub_cat"></li> <li class="sub_cat"></li> <li class="par_cat"></li> // this is the single element I need to select <li class="sub_cat"></li> <li class="sub_cat"></li> <li class="sub_cat current_sub"></li> // this is where I need to start searching <li class="par_cat"></li> <li class="sub_cat"></li> <li class="par_cat"></li> I need to traverse from the .current_sub , find the closest previous .par_cat and do stuff to it. .find("li.par_cat") returns the whole load of .par_cat (I've got about 30 on the page). I need

PHP - Find parent key of array

瘦欲@ 提交于 2019-11-26 11:34:58
问题 I\'m trying to find a way to return the value of an array\'s parent key. For example, from the array below I\'d like to find out the parent\'s key where $array[\'id\'] == \"0002\". The parent key is obvious because it\'s defined here (it would be \'products\'), but normally it\'d be dynamic, hence the problem. The \'id\' and value of \'id\' is known though. [0] => Array ( [data] => [id] => 0000 [name] => Swirl [categories] => Array ( [0] => Array ( [id] => 0001 [name] => Whirl [products] =>

How to get nodes lying inside a range with javascript?

[亡魂溺海] 提交于 2019-11-26 10:59:23
问题 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 magic*/; I\'ve been been thinking of a way for the last few hours and came up with this: var getNextNode = function(node, skipChildren){ //if there are child

Returning only simple paths in Neo4j Cypher query

僤鯓⒐⒋嵵緔 提交于 2019-11-26 09:37:37
问题 Given a query like the following: START n = node(123) MATCH p = n-[r:LIKES*..3]->x RETURN p; The result paths that I get with the query above contain cycles. How can I return only simple paths? Given this example: How can I avoid paths with repeated nodes like: [Neo, Morpheus, Trinity, Morpheus, Neo] 回答1: Specifying the uniqueness of paths is a planned feature of cypher. So right now we have to ascertain that no node is a duplicate in the path. There is an ALL predicate that must hold true

Post order traversal of binary tree without recursion

怎甘沉沦 提交于 2019-11-26 08:58:45
问题 What is the algorithm for doing a post order traversal of a binary tree WITHOUT using recursion? 回答1: Here's a link which provides two other solutions without using any visited flags. https://leetcode.com/problems/binary-tree-postorder-traversal/ This is obviously a stack-based solution due to the lack of parent pointer in the tree. (We wouldn't need a stack if there's parent pointer). We would push the root node to the stack first. While the stack is not empty, we keep pushing the left child