Example #1
0
/***************************************************************************
*  Função: GRA Inserir vertice
******/
GRA_tpCondRet GRA_InserirVertice(GRA_tppGrafo pGrafoParm, char *nomeVertice, void *pValor)
{
	tpGrafo *pGrafo = (tpGrafo*) pGrafoParm;
	tpVertice *pVertice;

	if (pGrafo == NULL)
	{
		return GRA_CondRetGrafoNaoFoiCriado;
	}

   if (ExisteVertice(pGrafo, nomeVertice))
   {
      return GRA_CondRetJaExiste;
   }

	MEM_Alloc(sizeof(tpVertice), (void **) &pVertice);
	if (pVertice == NULL)
	{
		return GRA_CondRetFaltouMemoria;
	}

	pVertice->nome = nomeVertice;
	pVertice->pValor = pValor;
	pVertice->destruirValor = pGrafo->destruirValor;

	LIS_CriarLista(&pVertice->pAntecessores, NULL, CompararVerticeENome);
	LIS_CriarLista(&pVertice->pSucessores, DestruirAresta, CompararArestaENome);

	pGrafo->pCorrente = pVertice;
	LIS_InserirElementoApos(pGrafo->pVertices, pVertice);

	return GRA_CondRetOK;
}
bool Grafo::RemoveVertice(int id) {
	bool retorno = false;
	string strErro;
	try {
		if (!ExisteVertice(id)) {
			throw 1;
		}
		Vertice * nVertice = new Vertice();
		this->lVertice[id] = *nVertice;
		//remove todas conexoes
		for (int i = 0; i < this->tamGrafo; i++) {
			if (!this->Direcionado())
				this->RemoveConexao(i,id);
		}
		this->nrElementos--;
		retorno = true;
	} catch(...) {
		retorno = false;
	}
	return retorno;
}