int heap::tout(){
assert(!empty());
int x = a[0];
int i = 0;
a[0] = a[s];
s--;
while (i <= parent(s) && a[i] < a[maxChild(i)]){
int m = maxChild(i);
int c = a[m];
a[i] = a[m];
a[m] = c;
i = m;
}
return x;
}
int heap::maxChild(int i){
assert(i<=parent(s));
if (right(i) > s) return left(i);
return (a[left(i)] > a[right(i)]) ? left(i) : right (i);
}
int main() {
srand((unsigned) time(nullptr));
int n = 100;
heap m(n);
for (int i = 0; i < 10; i++){
int x = rand() % n + 1;
cout << "Agregar " << x << ": ";
m.ins(x);
m.print();
}
cout << "Extraer " << m.tout() <<": ";
m.print();
}
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)