Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __NODE_HPP__
- #define __NODE_HPP__
- #include <stdlib.h>
- #include <stdio.h>
- #include <vector>
- class Edge;
- class Node
- {
- public:
- Node(int _id, char _val) : id(_id), val(_val), visited(false)
- {
- }
- virtual ~Node()
- {
- }
- void setVisited(bool v)
- {
- visited = v;
- }
- bool isVisited()
- {
- return visited;
- }
- int getId() const
- {
- return id;
- }
- void setId(int _id)
- {
- id = _id;
- }
- void setVal(int v)
- {
- val = v;
- }
- char getVal() const
- {
- return val;
- }
- void setDist(int d)
- {
- dist = d;
- }
- int getDist()
- {
- return dist;
- }
- void addNeighbour(Node *n)
- {
- neighbours.push_back(n);
- }
- std::vector<Node*>& getNeighbours()
- {
- return neighbours;
- }
- void addEdge(Edge *e)
- {
- edges.push_back(e);
- }
- std::vector<Edge*>& getEdges()
- {
- return edges;
- }
- void setPredecessor(Node *p)
- {
- predecessor = p;
- }
- Node* getPredecessor()
- {
- return predecessor;
- }
- void dumpNode()
- {
- printf("%d(%c) ->", id, val);
- int num = neighbours.size();
- for(int i = 0; i < num; ++i)
- {
- Node *n = neighbours[i];
- printf(" %d(%c)", n->getId(), n->getVal());
- }
- printf("\n");
- }
- bool operator ==(const Node &n)
- {
- return id == n.id;
- }
- protected:
- int id;
- int val;
- int dist;
- bool visited;
- Node *predecessor;
- std::vector<Node*> neighbours;
- std::vector<Edge*> edges;
- };
- class NodeComparator
- {
- public:
- NodeComparator()
- {
- }
- virtual ~NodeComparator()
- {
- }
- bool operator() (Node &lhs, Node &rhs)
- {
- return lhs.getDist() > rhs.getDist();
- }
- bool operator() (Node *&lhs, Node *&rhs)
- {
- return lhs->getDist() > rhs->getDist();
- }
- };
- #endif
Add Comment
Please, Sign In to add comment