File: VERTEX.CPP Implementation of a Vertex */ #include "vertex.h

advertisement
*/
VERTEX.CPP File:
Implementation of a Vertex
/*
"include "vertex.h#
"include "edge.h#
>include <string.h#
>include <iostream.h#
*/
.Construction of a Vertex
We only initialize default values
/*
)(Vertex::Vertex(): IDObject
{
;name = 0
;data = 0
}
)(Vertex::Vertex( char *n ): IDObject
{
;data = 0
;) name = strdup( n
}
*/
Destruction of a Vertex object
We take care of name allocation
/*
)(Vertex::~Vertex
{
) if ( name
;delete name
}
*/
oeprator= is implemented here so we can create a copy of our data
without pointer problems
it will not duplicate new vertices, just create the right pointers
to them
/*
) Vertex &Vertex::operator=( const Vertex &v
{
) if ( name
;delete name
;) name = strdup( v.name
;data = v.data
;id = v.id
handle edges //
;edges = v.edges
;return *this
}
*/
operator== so we can check if two vertices are the same
/*
bool Vertex::operator ==( const Vertex &v ) const
{
;)(return GetID() == v.GetID
}
*/
Add a new Edge to this Vertex
/*
) void Vertex::AddEdge( Edge *e
{
;) edges.Insert( e
;e->from = this
}
*/
Print out all Vertex information
/*
)(void Vertex::Print
{
;cout << "Vertex " << name << "(" << id << ")" << endl
;cout << "Color: " << data->color << endl
;cout << "d = " << data->d << ", f = " << data->f << endl
;cout << "Root is " << data->root->name << endl
;cout << "Parent is " << data->parent->name << endl
;" cout << "Edges to
;Edge *e
;)(edges.ResetIt
) ) )(while ( e = static_cast<Edge*>( edges.Next
{
;" " << cout << e->to->name
}
;cout << endl
}
Download