traversal

Finding all possible paths in graph

大兔子大兔子 提交于 2019-12-05 18:08:57
I'm looking for some algorithm which will help me find all possible paths in a graph. Everything I found so far is not fully satisfying. Let's imagine we have a graph (tree) like this one: And let's use some algorithm like Breadth-First Search or Depth-First Search . In return we'll get something like 1, 2, 4, (2), 5, (2), 6, (2), (1), 3, 7, 8, (7), 9 Which is how we go through this tree and this is not what I'm looking for. I'd love to get all paths, like: 1 1, 2 1, 2, 4 1, 2, 5 1, 2, 6 1, 3 1, 3, 7 1, 3, 7, 8 1, 3, 7, 9 The thing is that I want just to specify root node and algorithm should

How to Traverse a N-Ary Tree

≡放荡痞女 提交于 2019-12-05 18:04:43
My Tree/Node Class: import java.util.ArrayList; import java.util.List; public class Node<T> { private T data; private List<Node<T>> children; private Node<T> parent; public Node(T data) { this.data = data; this.children = new ArrayList<Node<T>>(); } public Node(Node<T> node) { this.data = (T) node.getData(); children = new ArrayList<Node<T>>(); } public void addChild(Node<T> child) { child.setParent(this); children.add(child); } public T getData() { return this.data; } public void setData(T data) { this.data = data; } public Node<T> getParent() { return this.parent; } public void setParent

Equivalent of $(this) in native javascript

坚强是说给别人听的谎言 提交于 2019-12-05 17:47:41
I wanted to add and event listener to a button and I am still relatively new on coding purely on javascript, so I don't know what are the native equivalent of $this in my code // the markup <ul class="menu"> <li><a href="#" data-something="value">text</a></li> <li><a href="#" data-something="value2">text2</a></li> </ul> var menu = document.querySelector(".menu"); menu.addEventListener("click", function(){ // console.log $(this).val // what I wanted is to get that data-attribute of the clicked item }); Within the event handler this will represent the element to which the event handler is bound.

How do you iterate over all configurations of m variables belonging to the same domain of size n?

為{幸葍}努か 提交于 2019-12-05 14:52:28
EDIT: My solution is added to the end of the question. Thanks for the hint. I'll just go with an example. Suppose I have an array with length n : arr = { 1, 4, 8, 2, 5, ... } If I want to traverse all combinations of TWO elements I would write: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { // do something with arr[i] and arr[j] } } I If I want to traverse all configurations of THREE elements I would simply add another layer of for iteration: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { // do something with arr[i] and arr[j] } } } What

Attach javascript/jquery event on dynamically created elements

白昼怎懂夜的黑 提交于 2019-12-05 11:11:49
I've seen a lot of different questions similar to this, but all of them generally targeted a specific selector. Please let me know if there is a duplicate somewhere and I've missed it. Take this scenario: You want to build a jquery plugin for a wordpress, drupal, or basically any site that uses third party functionality. Since you don't know ahead of time every specific event and selector you will need to target how would you add jquery/javascript functionality to elements that are created dynamically. Plus you don't know how the element is created (callback using ajax/php/etc). Example: I

Traversing with a Biapplicative

a 夏天 提交于 2019-12-05 10:28:22
问题 I was thinking about unzipping operations and realized that one way to express them is by traversing in a Biapplicative functor. import Data.Biapplicative class Traversable2 t where traverse2 :: Biapplicative p => (a -> p b c) -> t a -> p (t b) (t c) -- Note: sequence2 :: [(a,b)] -> ([a], [b]) sequence2 :: (Traversable2 t, Biapplicative p) => t (p b c) -> p (t b) (t c) sequence2 = traverse2 id instance Traversable2 [] where traverse2 _ [] = bipure [] [] traverse2 f (x : xs) = bimap (:) (:) (f

How to traverse stack in C++?

被刻印的时光 ゝ 提交于 2019-12-05 06:40:54
Is it possible to traverse std::stack in C++? Traversing using following method is not applicable. Because std::stack has no member end . std::stack<int> foo; // .. for (__typeof(foo.begin()) it = foo.begin(); it != foo.end(); it++) { // ... } Is it possible to traverse std::stack in C++? No. A stack is a data structure you should use when you are interested in placing elements on top and getting elements from the top. If you want an iterable stack, either use a different data structure for a stack role ( std::vector ?) or write one yourself. Rahul Tripathi I don't think that it is possible to

How I can traverse the HTML tree using Jsoup?

房东的猫 提交于 2019-12-05 05:03:41
I think this question has been asked, but I not found anything. From the Document element in Jsoup, how I can traverse for all elements in the HTML content? I was reading the documentation and I was thinking about using the childNodes() method, but it only takes the nodes from one leval below (what I understand). I think I can use some recursion with this method, but I want to know if there is a more appropriate/native way to do this. From Document (and any Node subclass), you can use the traverse(NodeVisitor) method. For example: document.traverse(new NodeVisitor() { public void head(Node

How can I store data in a table as a trie? (SQL Server)

為{幸葍}努か 提交于 2019-12-05 02:15:31
问题 To make things easier, the table contains all the words in the English dictionary. What I would like to do is be able to store the data as a trie. This way I can traverse the different branches of the trie and return the most relevant result. First, how do I store the data in the table as a trie? Second, how do I traverse the tree? If it helps at all, the suggestion in this previous question is where this question was sparked from. Please make sure it's SQL we're talking about. I understood

Get parent-child array from coredata

旧时模样 提交于 2019-12-04 20:03:54
I have a CoreData model that can contain an infinite number of children. And I want to display a list of each object, indented for readability like so Object Object first child first childs children first child children Object second child Object 2 Object also has children MOre children Childs Now I come from a PHP background. and in PHP I would create a simple array which Ill traverse with some functions to build this list but this still seems stupidly hard for me. I got a flat array which basically has items like this: array.name = @"Name"; array.children = nil or coredata rows array.parent