Exception in thread “main” java.util.NoSuchElementException: No line found – Using scanner input [duplicate]

The problem is you are closing System.in (Scanner.close() closes the underlying stream). Once you do that, it stays closed, and is unavailable for input. You don’t normally want to do that with standard input: String searchedNode; Scanner in = new Scanner(System.in); System.out.println(“Enter the name you would like to remove from the list: “); searchedNode = … Read more

How to swap DOM child nodes in JavaScript?

There is no need for cloning. You can just move one node before the other. The .insertBefore() method will take it from its current location and insert it somewhere else (thus moving it): childNode[4].parentNode.insertBefore(childNode[4], childNode[3]); You get the parent of the node. You then call the insertBefore method on the parent and you pass it … Read more

Hypergraph with networkx

Did you want something like this use nx.draw_networkx_nodes using nodelist parameter: # Author: Aric Hagberg ([email protected]) import matplotlib.pyplot as plt import networkx as nx G = nx.Graph() G.add_edge(‘a’, ‘b’, weight=0.6) G.add_edge(‘a’, ‘c’, weight=0.2) G.add_edge(‘c’, ‘d’, weight=0.1) G.add_edge(‘c’, ‘e’, weight=0.7) G.add_edge(‘c’, ‘f’, weight=0.9) G.add_edge(‘a’, ‘d’, weight=0.3) elarge = [(u, v) for (u, v, d) in G.edges(data=True) … Read more

Node.js server that accepts POST requests

The following code shows how to read values from an HTML form. As @pimvdb said you need to use the request.on(‘data’…) to capture the contents of the body. const http = require(‘http’) const server = http.createServer(function(request, response) { console.dir(request.param) if (request.method == ‘POST’) { console.log(‘POST’) var body = ” request.on(‘data’, function(data) { body += data … Read more

What is the difference between node.nextSibling and ChildNode.nextElementSibling?

nextElementSibling always returns an element. nextSibling can return any kind of node. They are the same for your example, but different in other cases, e.g.: <p><span id=”span-01″>Here is span-01</span> Some text at the top level <span id=”span-02″>Here is span-02</span></p> In this case, document.getElementById(‘span-01’).nextElementSibling is span-02, but document.getElementById(‘span-01’).nextSibling is the text node containing “Some text at … Read more

Why is NULL undeclared?

NULL is not a built-in constant in the C or C++ languages. In fact, in C++ it’s more or less obsolete, just use a plain literal 0 instead, the compiler will do the right thing depending on the context. In newer C++ (C++11 and higher), use nullptr (as pointed out in a comment, thanks). Otherwise, … Read more

Graph auto-layout algorithm

You will find http://graphdrawing.org/ and this tutorial, by Roberto Tamassia, professor at Brown University, quite helpful. I like a lot Force-Directed Techniques (pp. 66-72 in the tutorial) like the Spring Embedder. You assume there is a spring or other force between any two adjacent nodes and let nature (simulation) do the work 🙂