本文整理汇总了C++中Heap::GetTamHeap方法的典型用法代码示例。如果您正苦于以下问题:C++ Heap::GetTamHeap方法的具体用法?C++ Heap::GetTamHeap怎么用?C++ Heap::GetTamHeap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap::GetTamHeap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//Constutor de Copia
Heap::Heap(const Heap & cHeap) {
this->tamHeapMax = cHeap.GetTamHeapMax();
this->tamHeap = cHeap.GetTamHeap();
this->arrayHeap = new Aresta [ this->tamHeapMax ];
Aresta * cAresta;
for (int i=0; i < this->tamHeap; i++) {
cAresta = cHeap.GetAresta(i);
this->Push(cAresta);
}
this->tipo = cHeap.GetTipo();
}
示例2: Heap
std::vector<Aresta *> Grafo::Kruskal() {
std::vector<Aresta *> retorno;
//so faz se nao eh direcionado
if (!this->Direcionado()) {
//conjunto de vertices e ranks
std::vector<int> ranks;
//inicializa conjunto de vertices e ranks
Heap * nHeap;
int tamHeapMax = 0;
conjKruskal.clear();
ranks.clear();
for (int i = 0; i < tamGrafo; i++) {
this->conjKruskal.push_back(i);
ranks.push_back(1);
for (int j =0; j < tamGrafo; j++)
if (this->Conexao(i,j))
tamHeapMax++;
}
nHeap = new Heap(tamHeapMax);
nHeap->SetTipo(MINIMO);
for (int i = 0; i < tamGrafo; i++) {
for (int j =i; j < tamGrafo; j++) {
if (this->Conexao(i,j)) {
Aresta * nAresta = new Aresta(*this->GetVertice(i).GetAresta(j));
nHeap->Push(nAresta);
}
}
}
//nHeap->ListaHeap();
int id1;
int id2;
int id1tmp;
int id2tmp;
std::vector<Aresta *> lArestas;
while(nHeap->GetTamHeap() > 0 ) {
Aresta * cAresta = nHeap->Pop();
id1 = cAresta->GetId1();
id2 = cAresta->GetId2();
//cout << "id1: " << id1 << " id2:" << id2 << endl;
if ((id1tmp = this->BuscaKruskal(id1)) != (id2tmp = BuscaKruskal(id2))) {
//cout << "conjuntos diferentes: " << "id1: " << this->BuscaKruskal(id1) << " id2: " << this->BuscaKruskal(id2) << endl;
retorno.push_back(cAresta);
if (ranks[id1tmp] != ranks[id2tmp]) {
int maior = (ranks[id1tmp] > ranks[id2tmp] ? id1tmp : id2tmp);
int menor = (ranks[id2tmp] > ranks[id1tmp] ? id1tmp : id2tmp);
conjKruskal[menor] = maior;
//cout << "ranks: " << " menor: " << ranks[menor] << "maior: " << ranks[maior] << endl;
} else {
conjKruskal[id2tmp] = id1tmp;
ranks[id1tmp] += 1;
//cout << "aumentou rank" << endl;
}
}
}
}
return retorno;
}