39 m_pVertex0(p0), m_pVertex1(p1), m_nIndex(index){
93 if(pEdge ==
nullptr)
return;
150 for(
UINT i=0; i<n; i++)
205 const int n = (int)pAdjList->size();
206 auto& adjacencylist = *pAdjList;
208 for(
int i=0; i<n-1; i++)
209 std::swap(adjacencylist[i], adjacencylist[
m_cRandom.
randn(i, n-1)]);
211 for(
CEdge* pEdge: *pAdjList){
212 CVertex* next = pEdge->GetNextVertex(current);
214 if(next !=
nullptr && !next->
Marked()){
215 result.push_back(pEdge->GetIndex());
234 FILE* output =
nullptr;
235 fopen_s(&output,
"graph.txt",
"wt");
242 p->GetVertexIndices(i, j);
243 fprintf(output,
"(%u, %u)\n", i, j);
CVertex * GetNextVertex(CVertex *p)
Get vertex at other end of edge.
size_t GetDegree()
Get degree.
UINT GetIndex()
Get index;.
UINT m_nNumEdges
Number of edges.
CRandom m_cRandom
Random number generator.
UINT m_nIndex
Index into vertex list.
void Mark(bool b=true)
Mark or unmark.
#define fprintf_s
fprintf_s for *NIX.
UINT randn()
Get a random unsigned integer.
void PrintGraph()
Print the graph to a text file.
std::queue< CVertex * > m_qBFSQueue
Queue for breadth-first search.
Header for helper functions.
std::vector< CEdge * > m_vEdgeList
Edge list.
unsigned int UINT
Abbreviation for unsigned integer.
void InsertAdjacency(CEdge *pEdge)
Add an edge to the edge list.
void SetIndex(const UINT n)
Set index.
void InsertEdge(const UINT i, const UINT j)
Insert an edge.
CVertex * m_pVertex0
Vertex at one end of the edge,.
void Mark(bool b=true)
Mark or unmark.
UINT BFSF(std::vector< UINT > &result)
Breadth-first spanning forest.
std::vector< CEdge * > m_vAdjacencyList
Adjacency list.
UINT GetIndex()
Get index;.
CVertex * m_pVertex1
Vertex at the other end of the edge.
Header for the graph CGraph and its vertices CVertex and edges CEdge.
CEdge(CVertex *p0, CVertex *p1, UINT index)
Constructor.
void fopen_s(FILE **stream, const char *name, const char *fmt)
fopen_s for *NIX.
CGraph(const UINT n)
Constructor.
Header for the pseudo-random number generator CRandom.
UINT m_nNumVerts
Number of vertices.
void srand()
Seed the random number generator.
std::vector< CEdge * > * GetAdjacencyList()
Get adjacency list.
UINT m_nIndex
Index into edge list.
CVertex * m_pVertexList
Vertex list.
void GetVertexIndices(UINT &i0, UINT &i1)
Get vertex indices.