Dijkstra Algorithm view (Node, Edges)

Here’s one idea that would work well.

When the mouse is clicked, look to see if it was clicked on a node.

If it wasn’t, that click creates a node.

If, however, the click WAS on an existing node, you’re starting to create an edge. When this occurs, you must wait for the next click to happen. If the next click is on a node, create an edge between those two nodes. If that next click is not on a node, however, then nothing happens.


You can also remove nodes and edges this way if you’re clever! If you click a node to start an edge, but then don’t click a second node, that can mean to remove the clicked node (don’t forget to remove all edges that connect to it too!).

Also, if you try to make an edge between two nodes that already have an edge, that can mean to remove that edge. Essentially it’s toggling edges between the clicked nodes, not just creating one.


Implementation of this is left as part of the exercise. Do post what you come up with - It’d be most helpful for others!

1 Like