fork download
  1. template <class Item>
  2. void d_ary_fixDown2(Item a[], int node, int n){
  3. int first_child = node*d + 1 - (d - 1);
  4. int last_child = node*d + 1;
  5. int max_child = first_child; /*Начнем с самого первого*/
  6.  
  7. while(node*d + 1 - (d - 1) <= n){
  8. int j = node*d + 1 - (d - 1);
  9.  
  10. /*Ищем максимального потомка среди всех d потомков узла node*/
  11. for(int i = first_child; i <= last_child; i++)
  12. if(a[i] > a[max_child])
  13. max_child = i;
  14. /*Если потомок max_child больше своего родителя, то меняем их местами*/
  15. if(a[max_child] > a[(max_child + d - 2) / d])
  16. std::swap(a[max_child], a[(max_child + d - 2) / d]);
  17.  
  18. node = j;
  19. }
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void d_ary_fixDown2(Item*, int, int)':
prog.cpp:3:25: error: 'd' was not declared in this scope
  int first_child = node*d + 1 - (d - 1);
                         ^
prog.cpp:16:4: error: 'swap' is not a member of 'std'
    std::swap(a[max_child], a[(max_child + d - 2) / d]);
    ^
stdout
Standard output is empty