Guest User

Untitled

a guest
May 26th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #ifndef __NODE_HPP__
  2. #define __NODE_HPP__
  3.  
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <vector>
  7.  
  8. class Edge;
  9.  
  10. class Node
  11. {
  12. public:
  13. Node(int _id, char _val) : id(_id), val(_val), visited(false)
  14. {
  15. }
  16.  
  17. virtual ~Node()
  18. {
  19. }
  20.  
  21. void setVisited(bool v)
  22. {
  23. visited = v;
  24. }
  25.  
  26. bool isVisited()
  27. {
  28. return visited;
  29. }
  30.  
  31. int getId() const
  32. {
  33. return id;
  34. }
  35.  
  36. void setId(int _id)
  37. {
  38. id = _id;
  39. }
  40.  
  41. void setVal(int v)
  42. {
  43. val = v;
  44. }
  45.  
  46. char getVal() const
  47. {
  48. return val;
  49. }
  50.  
  51. void setDist(int d)
  52. {
  53. dist = d;
  54. }
  55.  
  56. int getDist()
  57. {
  58. return dist;
  59. }
  60.  
  61. void addNeighbour(Node *n)
  62. {
  63. neighbours.push_back(n);
  64. }
  65.  
  66. std::vector<Node*>& getNeighbours()
  67. {
  68. return neighbours;
  69. }
  70.  
  71. void addEdge(Edge *e)
  72. {
  73. edges.push_back(e);
  74. }
  75.  
  76. std::vector<Edge*>& getEdges()
  77. {
  78. return edges;
  79. }
  80.  
  81. void setPredecessor(Node *p)
  82. {
  83. predecessor = p;
  84. }
  85.  
  86. Node* getPredecessor()
  87. {
  88. return predecessor;
  89. }
  90.  
  91. void dumpNode()
  92. {
  93. printf("%d(%c) ->", id, val);
  94. int num = neighbours.size();
  95. for(int i = 0; i < num; ++i)
  96. {
  97. Node *n = neighbours[i];
  98. printf(" %d(%c)", n->getId(), n->getVal());
  99. }
  100. printf("\n");
  101. }
  102.  
  103. bool operator ==(const Node &n)
  104. {
  105. return id == n.id;
  106. }
  107.  
  108. protected:
  109. int id;
  110. int val;
  111. int dist;
  112.  
  113. bool visited;
  114.  
  115. Node *predecessor;
  116.  
  117. std::vector<Node*> neighbours;
  118. std::vector<Edge*> edges;
  119. };
  120.  
  121. class NodeComparator
  122. {
  123. public:
  124. NodeComparator()
  125. {
  126. }
  127.  
  128. virtual ~NodeComparator()
  129. {
  130. }
  131.  
  132. bool operator() (Node &lhs, Node &rhs)
  133. {
  134. return lhs.getDist() > rhs.getDist();
  135. }
  136.  
  137. bool operator() (Node *&lhs, Node *&rhs)
  138. {
  139. return lhs->getDist() > rhs->getDist();
  140. }
  141. };
  142.  
  143. #endif
Add Comment
Please, Sign In to add comment