연결 리스트와 같이 마지막 노드로 이동하여 추가하는 과정을 거치면 된다.
void Graph::Vappend(int data) {
VORTEX* newVortex = new VORTEX;
newVortex->Data = data;
newVortex->Ehead = nullptr;
newVortex->next = nullptr;
if (!graph->Vhead)
graph->Vhead = newVortex;
else {
VORTEX* temp = nullptr;
temp = graph->Vhead;
while (temp->next) {
temp = temp->next;
}
temp->next = newVortex;
}
}
void Graph::Eappend(VORTEX* from, VORTEX* to) {
if (!from || !to) {
std::cout << "없는 정점입니다...\n";
return;
}
EDGE* newEdge = new EDGE;
newEdge->from = from;
newEdge->to = to;
newEdge->next = nullptr;
if (!from->Ehead)
from->Ehead = newEdge;
else {
EDGE* temp = nullptr;
temp = from->Ehead;
while (temp->next)
temp = temp->next;
temp->next = newEdge;
}
}
VORTEX* Graph::getVortex(int data) {
if (!graph->Vhead)
return nullptr;
VORTEX* temp = nullptr;
temp = graph->Vhead;
while (temp) {
if (temp->Data == data) {
return temp;
}
temp = temp->next;
}
return temp;
}