-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vertex.cpp
66 lines (54 loc) · 1.06 KB
/
Vertex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Vertex.h"
Vertex::Vertex() //constructor
{
this->m_key = 0;
this->m_pEHead = nullptr;
this->m_pNext = nullptr;
this->m_size = 0;
}
Vertex::Vertex(int key) //constructor overload
{
this->m_key = key;
this->m_pEHead = nullptr;
this->m_pNext = nullptr;
this->m_size = 0;
}
Vertex::~Vertex()
{
}
void Vertex::SetNext(Vertex * pNext) //set next node
{
this->m_pNext = pNext;
}
int Vertex::GetKey() const //return key
{
return this->m_key;
}
Vertex * Vertex::GetNext() const //return next node
{
return this->m_pNext;
}
int Vertex::Size() const //return size
{
return this->m_size;
}
void Vertex::AddEdge(int edgeKey, int weight) //addedge
{
Edge * pNEdge = new Edge(edgeKey, weight); //make new edge
if (this->m_pEHead == NULL) { //if edge list is empty
this->m_pEHead = pNEdge; //make new edge as head
return;
}
Edge * pCur = m_pEHead;
while (pCur->GetNext() != NULL) {
pCur = pCur->GetNext();
}
pCur->SetNext(pNEdge); //add edge
}
Edge * Vertex::GetHeadOfEdge() const //return head
{
return this->m_pEHead;
}
void Vertex::Clear()
{
}