Tree Class Reference

A labelled, free tree. More...

#include <Tree.hpp>

List of all members.

Public Member Functions

 Tree ()
 Default constructor. Creates an empty Tree, one with no vertices or edges.
 Tree (unsigned int order, int *levelSequence)
 Constructor. Creates a Tree of the given order (i.e. number of vertices), and the given level sequence (see TreeGenerator.hpp and TreeGenerator.cpp for details). Essentially, the level sequence is an array which describes which edges the Tree contains.
 Tree (const Tree &that)
 Copy constructor. Copies that Tree into this object.
 ~Tree ()
 Destructor. Automatically called when this Tree goes out of scope. Frees the memory this Tree takes up.
unsigned int getOrder () const
 Get the number of vertices in this Tree.
unsigned int getDegree (unsigned int v) const
 Get the degree of the given vertex v. Degree is the number of edges incident on that vertex.
std::vector< EdgegetEdges () const
 Get a list of edges in this Tree. Gets a vector containing each undirected edge present in this Tree, stored as Edge structs.
void getDegreeSequence (std::vector< unsigned int > &degreeSequence) const
 Gets the degree sequence of this Tree. Sorts the degree sequence (a list of positive integers) from largest to smallest.
void getPathNums (std::vector< unsigned int > &pathNums) const
 Gets the path sequence of this Tree. List of positive integers, each of which is the number of paths of the length given by its position in the vector (first position is length 0, second position is length 1, etc.). This function is a wrapper for the private function pathNumsDfs().
void print () const
 Prints a list of the edges of this Tree.
Treeoperator= (const Tree &rhs)
 Overloaded assignment operator. Manages memory when assignment operator is used with this oject. E.g. tree1 = tree2;.

Detailed Description

A labelled, free tree.

The labels are arbitrary, but useful for operating on the tree.

Definition at line 26 of file Tree.hpp.


Constructor & Destructor Documentation

Tree::Tree ( unsigned int  order,
int *  levelSequence 
)

Constructor. Creates a Tree of the given order (i.e. number of vertices), and the given level sequence (see TreeGenerator.hpp and TreeGenerator.cpp for details). Essentially, the level sequence is an array which describes which edges the Tree contains.

Parameters:
order The number of vertices in the Tree. Should also be the size of the levelSequence array.
levelSequence Array which describes the structure of the Tree. See the TreeGenerator class for more information on how this array is defined and created.
Precondition:
The order should be equal to the size of the levelSequence array.
Postcondition:
The level sequence is unchanged, and this object is a Tree with edges as described by the level sequence array.

Definition at line 29 of file Tree.cpp.

Tree::Tree ( const Tree that  ) 

Copy constructor. Copies that Tree into this object.

Parameters:
that The Tree to copy into this object.
Precondition:
that should be a valid Tree object.
Postcondition:
This object will be an exact copy in memory of that Tree, and that object will not be modified at all.

Definition at line 70 of file Tree.cpp.


Member Function Documentation

unsigned int Tree::getDegree ( unsigned int  v  )  const [inline]

Get the degree of the given vertex v. Degree is the number of edges incident on that vertex.

Parameters:
v The vertex you want to know the degree of.
Precondition:
v should be a positive integer, 0 <= v < n, where n is the order of this Tree. This is because the vertex labels range from 0 to n - 1.
Postcondition:
Doesn't modify this Tree object at all.
Returns:
Positive integer number of edges incident with vertex v. Returns 0 if the precondition for v is not met.

Definition at line 79 of file Tree.hpp.

void Tree::getDegreeSequence ( std::vector< unsigned int > &  degreeSequence  )  const

Gets the degree sequence of this Tree. Sorts the degree sequence (a list of positive integers) from largest to smallest.

Parameters:
degreeSequence This vector will be cleared and its new contents will be the sorted degree sequence.
Postcondition:
Doesn't modify this Tree object at all.

Definition at line 122 of file Tree.cpp.

std::vector< Edge > Tree::getEdges (  )  const

Get a list of edges in this Tree. Gets a vector containing each undirected edge present in this Tree, stored as Edge structs.

Postcondition:
Doesn't modify this Tree object at all.
Returns:
A vector (i.e. an STL dynamic array) which contains the edges of this Tree in no particular order.

Definition at line 101 of file Tree.cpp.

unsigned int Tree::getOrder (  )  const [inline]

Get the number of vertices in this Tree.

Postcondition:
Doesn't modify this Tree object at all.
Returns:
Positive integer number of vertices in this Tree.

Definition at line 69 of file Tree.hpp.

void Tree::getPathNums ( std::vector< unsigned int > &  pathNums  )  const

Gets the path sequence of this Tree. List of positive integers, each of which is the number of paths of the length given by its position in the vector (first position is length 0, second position is length 1, etc.). This function is a wrapper for the private function pathNumsDfs().

Parameters:
pathNums This vector will be cleared and its new contents will be the path sequence as described above.
Postcondition:
Doesn't modify this Tree object at all.

Definition at line 130 of file Tree.cpp.

Tree & Tree::operator= ( const Tree rhs  ) 

Overloaded assignment operator. Manages memory when assignment operator is used with this oject. E.g. tree1 = tree2;.

Parameters:
rhs Tree on the right hand side of the equals sign.
Precondition:
rhs should be a valid Tree object.
Postcondition:
This Tree will be an exact duplicate of the Tree rhs.

Definition at line 167 of file Tree.cpp.

void Tree::print (  )  const

Prints a list of the edges of this Tree.

Postcondition:
Doesn't modify this Tree object at all.

Definition at line 157 of file Tree.cpp.


The documentation for this class was generated from the following files:
 All Classes Files Functions
Generated on Mon Apr 1 10:56:03 2013 by  doxygen 1.6.3