Guest User

Untitled

a guest
Nov 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public class Vector
  2. {
  3. public Node from;
  4. public Node to;
  5. public float weight;
  6. public Vector(Node from, Node to, float weight)
  7. {
  8. this.from = from;
  9. this.to = to;
  10. this.weight = weight;
  11. }
  12. }
  13.  
  14. public class Node
  15. {
  16. private int _value;
  17. private HashSet<Vector> _children;
  18.  
  19. public Node(int v)
  20. {
  21. _value = v;
  22. _children = new HashSet<Vector>();
  23. }
  24.  
  25. public int value()
  26. {
  27. return _value;
  28. }
  29.  
  30. public void addChild(Node n , float weight)
  31. {
  32. Vector a = new Vector(this, n, weight);
  33. _children.Add(a);
  34. }
  35.  
  36. public List<Vector> children()
  37. {
  38. return _children.ToList();
  39. }
  40. }
  41.  
  42. public class Graph
  43. {
  44. private Dictionary<int, Node> nodes;
  45. public Graph()
  46. {
  47. nodes = new Dictionary<int, Node>();
  48. }
  49.  
  50. public int create()
  51. {
  52. Node n = new Node(nodes.Count + 1);
  53. nodes.Add(n.value(), n);
  54. return n.value();
  55. }
  56.  
  57. public void connect(int father, int child, float weight)
  58. {
  59. Node f, c;
  60. nodes.TryGetValue(father, out f);
  61. nodes.TryGetValue(child, out c);
  62. f.addChild(c, weight);
  63. c.addChild(f, weight);
  64. }
  65.  
  66. public Graph Kruskal()
  67. {
  68.  
  69. }
Add Comment
Please, Sign In to add comment