traversal

java array traversal in circular manner

北城余情 提交于 2019-12-02 23:49:14
I have an array which have 1 2 3 4 5 values. array a = [ 1 , 2, 3, 4, 5] Now i want to traverse it in circular manner. like i want to print 2 3 4 5 1 or 3 4 5 1 2 or 5 1 2 3 4 and so on. any algorithm on this? Edit: I want to print all the combination in circular manner. i don't want to state starting point at its initial phase. int start = ... for (int i = 0; i < a.length; i++) { System.out.println(a[(start + i) % a.length]); } (If you want to iterate the array backwards from start , change start + i to start - i in the array subscript expression.) I should note that this is probably not the

Find the element before and after a specific element

浪子不回头ぞ 提交于 2019-12-02 21:44:21
I have a list with links I use with tabs. It looks like this: <ul> <li><a href="#">First tab</a></li> <li><a href="#">Second tab</a></li> <li class="active"><a href="#">Active tab</a></li> <li><a href="#">Fourth tab</a></li> <li><a href="#">Fifth tab</a></li> </ul> How can I find the list element before and after the active tab? (In this case, the second and fourth tab). Tried using find, with no success :( $("li.active").next(); and $("li.active").prev(); 来源: https://stackoverflow.com/questions/929670/find-the-element-before-and-after-a-specific-element

Simple Graph Search Algorithm in SQL (PostgreSQL)

痴心易碎 提交于 2019-12-02 20:57:42
I've implemented a graph of nodes in PostgreSQL (not a tree) the structure of the table is in this format id | node1 | node2 -------------------- 1 | 1 | 2 2 | 1 | 3 3 | 4 | 1 4 | 5 | 1 5 | 1 | 6 This shows the relationships between the node 1 and the nodes it is connected to. My Problem ...is that i need a function or method to find a particular node path in sql. I want to call a function like SELECT getGraphPath(startnode,targetnode) and this will display the path in any form(rows, or strings) e.g. SELECT getGraphPath(1,18) gives: [1]-->[3]-->[17]-->[18] [1]-->[4]-->[10]-->[18] or even rows:

C# Graph Traversal

♀尐吖头ヾ 提交于 2019-12-02 20:50:30
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) { if (!visited.ContainsKey(neighbor)) { visited.Add(neighbor, false); worklist.Enqueue(neighbor); } } } I can use this to find a target node in the graph. The worklist dequeues (or pops) the items as the worklist is processed. Once I find the target how can I return the

Quicker to os.walk or glob?

这一生的挚爱 提交于 2019-12-02 17:40:56
I'm messing around with file lookups in python on a large hard disk. I've been looking at os.walk and glob. I usually use os.walk as I find it much neater and seems to be quicker (for usual size directories). Has anyone got any experience with them both and could say which is more efficient? As I say, glob seems to be slower, but you can use wildcards etc, were as with walk, you have to filter results. Here is an example of looking up core dumps. core = re.compile(r"core\.\d*") for root, dirs, files in os.walk("/path/to/dir/") for file in files: if core.search(file): path = os.path.join(root

How can I traverse/iterate an STL map?

与世无争的帅哥 提交于 2019-12-02 14:30:14
In want to traverse an STL map. I don't want to use its key. I don't care about the ordering, I just look for a way to access all elements it contains. How can I do this? Yes, you can traverse a Standard Library map . This is the basic method used to traverse a map , and serves as guidance to traverse any Standard Library collection: C++03/C++11: #include <cstdlib> #include <map> #include <string> using namespace std; int main() { typedef map<int,string> MyMap; MyMap my_map; // ... magic for( MyMap::const_iterator it = my_map.begin(); it != my_map.end(); ++it ) { int key = it->first; string

How to traverse SimpleXML to edit text nodes?

我是研究僧i 提交于 2019-12-02 11:19:17
I need to implement the following algorithm with SimpleXML: put a XML fragment string into a SimpleXML object; traverse all the nodes, selecting text nodes; edit the text node (example convert to upper case); return the xml as string. PROBLEMS: How to load a XML with named entities (ex.   ). To traverse XML to get only text nodes... With $sx->xpath('//text()'); I can not edit the nodes, how to select text nodes to edition? You can override the text content of a node returned by a SimpleXML XPath query by assigning to $node[0] , e.g. foreach ( $sx->xpath('//text()') as $text_node ) { $text_node

How to get hostname from IP address from file similar to /etc/hosts

帅比萌擦擦* 提交于 2019-12-02 09:30:42
I have a file which maps IP Address to hostname. Its format is similar to hosts file and contains a list of ipaddress to hostname mapping. eg. 10.200.99.1 master1 10.200.99.2 master2 10.200.99.3 master3 10.200.99.4 slave1 10.200.99.5 slave2 10.200.99.6 slave3 ... ... ... I would like to obtain hostname from a given ipaddress using bash script. How can i do so? You can try that : sh script.sh listofip #!/bin/bash echo "IP ?" echo -n "(Value and press Enter) :" read ip while read line do #VARIABLES file1=$line mip=$(echo $file1 | awk '{print $1}') name=$(echo $file1 | awk '{print $2}') if [ "

Multiple goal search on XML nodes in SQL Server

元气小坏坏 提交于 2019-12-02 04:02:35
I have a Process table in SQL Server like this: workflowXML column has values like this: sample1 (ProcessID=1) workflowXML of sample1: <process> <Event type="start" id="StartEvent_1" name="Start"> <outgoing>SequenceFlow_0z7u86p</outgoing> <outgoing>SequenceFlow_1onkt3z</outgoing> </Event> <task type="" id="Task_0a7vu1x" name="D"> <incoming>SequenceFlow_108ajnm</incoming> <incoming>SequenceFlow_1onkt3z</incoming> <outgoing>SequenceFlow_01clcmz</outgoing> </task> <task type="goal" id="Task_00ijt4n" name="B"> <incoming>SequenceFlow_17q1ecq</incoming> <incoming>SequenceFlow_0q9j3et</incoming>

<HTMLDivElement> has no method 'siblings'

为君一笑 提交于 2019-12-01 18:19:50
Im trying to change a sibling of a div element and this is the statement i used $('.edit').click(function(){ this.siblings('.innerInfo').html("success"); }); It keeps throwing the <HTMLDivElement> has no method 'siblings' exception, and i really cant figure out why. I've initiated jQuery and ive started the script on document.ready thanks for your help! Use $(this) instead of this . You're should reference $(this) like: $('.edit').click(function(){ $(this).siblings('.innerInfo').html("success"); }); 来源: https://stackoverflow.com/questions/6229198/htmldivelement-has-no-method-siblings