Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Graph {
- private:
- int VertexCount;
- List<Vertex> VertexList;
- public:
- Graph(int VC) {
- VertexCount = VC;
- VertexList = List<Vertex>(); }
- void AddVertex(Vertex* Add) {
- if(!FindVertex(Add->ID)) {
- VertexList.Add(Add); } }
- void AddEdge(Vertex* A, Vertex* B, bool TwoWay = 0) {
- Edge* New = new Edge(A, B);
- A->Neighbours.Add(New);
- if(TwoWay) {
- Edge* NewB = new Edge(B, A);
- B->Neighbours.Add(NewB); } }
- void RemoveVertex(Vertex* R) {
- VertexList.Reset();
- while(Vertex* c = VertexList.current) {
- c->Neighbours.Reset();
- while(Edge* n = c->Neighbours.current) {
- if(n->From == R || n->To == R) {
- c->Neighbours.Remove(n); }
- c->Neighbours.Next(); }
- VertexList.Next(); } }
- void RemoveEdge(Vertex* A, Vertex* B, bool TwoWay = 0) {
- A->Neighbours.Reset();
- while(Edge* n = A->Neighbours.current) {
- if(n->To == B) {
- A->Neighbours.Remove(n); }
- A->Neighbours.Next(); }
- if(TwoWay) {
- B->Neighbours.Reset();
- while(Edge* n = B->Neighbours.current) {
- if(n->To == A) {
- B->Neighbours.Remove(n); }
- B->Neighbours.Next(); } } }
- Vertex* FindVertex(int ID) {
- Vertex* Prev = NULL;
- Vertex* Tmp = First;
- while(Tmp) {
- if(Tmp->ID == ID) return Tmp;
- Prev = Tmp;
- Tmp = Tmp->Next; }
- return NULL; }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement