void InsertHeap::sort(vector<int> & array) { vector<int> temp; HeapTree *tree = new HeapTree(temp); for (int i = 0; i < (int)array.size(); ++i) { tree->insert(array[i]); } for (int i = array.size()-1; i >= 0; --i) { array[i] = tree->remove(); } tree->print(); delete tree; }
void prim::mstPrim(GraphManipulator * gm, vertex_ < string > *root) { list < vertex_ < string > *>Vertexs = gm->getVertexs(); initVertexs(Vertexs); root->setKey(0); HeapTree < string > *Q = new HeapTree < string > (); fillHeapTree(Vertexs, Q); Q->heapMin(); while (!Q->empty()) { vertex_ < string > u = Q->extractMin(); list < edge_ < string >> edges = gm->getEdges(u); list < edge_ < string >>::iterator itEdges; for (itEdges = edges.begin(); itEdges != edges.end(); itEdges++) { vertex_ < string > *vertexAdj = gm->getVertexAttributes((*itEdges).getVertex()); if (Q->search((*vertexAdj)) && (*itEdges).getWeight() < vertexAdj->getKey()) { (*vertexAdj).setFather(u.getValue()); (*vertexAdj).setKey((*itEdges).getWeight()); Q->refreshHeap((*vertexAdj)); Q->heapMin(); } } } }
int main(void){ HeapTree<int> Struct; Struct.add(3); cout << (int)Struct.remove(NULL); return 0; }
int main() { HeapTree tree; tree.push(20);//INSERT ELEMENTS tree.push(15); tree.push(9); tree.push(8); tree.push(5); tree.push(3); tree.push(7); tree.push(6); tree.push(2); tree.push(1); tree.push(100); tree.push(12); tree.displayAll();//DISPLAY ALL ELEMENTS std::cout<<"Popped: "<<tree.popHigh()<<std::endl; std::cout<<"Popped: "<<tree.popHigh()<<std::endl; tree.displayAll(); return 0; }