ListaAdjacente::~ListaAdjacente() { Aresta * p = origem; while(p != NULL){ Aresta * aux = p; p = p->getProx(); delete aux; } }
bool ListaAdjacente::hasInList(int n) { Aresta * p = origem; while(p != NULL){ if(p->getId() == n) return true; p = p->getProx(); } return false; }
void ListaAdjacente::removeFirst() { if(origem == NULL) return; Aresta * p = origem; origem = p->getProx(); size--; delete p; }
int ListaAdjacente::getSize(){ Aresta * p = origem; int count = 0; while(p != NULL){ count++; p = p->getProx(); } return count; }
string ListaAdjacente::printAdjacencias() { stringstream ss; Aresta * p = origem; while(p != NULL){ ss << p->getId() << " - Força: " << p->getForca() << endl; p = p->getProx(); } ss << endl; return ss.str(); }
void ListaAdjacente::removeByIndex(int pos){ if(origem == NULL) return; if(origem->getId() == pos){ removeFirst(); return; } Aresta * p = origem; while(p->getProx() != NULL && p->getProx()->getId() != pos) p = p->getProx(); if (p->getProx() == NULL) return; Aresta * aux = p->getProx(); p->setProx(aux->getProx()); --size; delete aux; }