title: Minimum Spanning Tree of weighted graph
body: <p>I need to write a predicate that creates a minimum spanning tree of a weighted undirected graph, using <a href="https://en.wikipedia.org/wiki/Prim%27s_algorithm" rel="nofollow noreferrer">Prim's Algorithm</a>. This is what I have so far:</p>
  
  <pre><code>% call the recursive predicate with the list of all nodes and
  %    one element (in this case the last one).
  mst(T) :- nodes(N), last(N,E), mst(T,N,E).
  
  % The element E is added to the visited list and removed from the toVisit list.
  mst(T,N,E) :- append(T,E,S), delete(R,E,L)...
  </code></pre>
  
  <p>Then the <code>toVisit</code> list should be sorted according to the distance of the edges connected to any of the nodes in the visited list. Any suggestions on how to do this?</p>