@TopToster

Не работает функция. Что лучше сделать?

int left_child(int i){
   return 2*i+1;
}
int right_child(int i){
   return 2*i+2;
}
typedef struct{
   int quantity;
   int *val;
} binary_tree;
void shift_down(binary_tree *s,int pos){
    int leftchild=left_child(pos);
    int rightchild=right_child(pos);
    if (right_child(pos) < s->quantity){
        if (s->val[leftchild] > s->val[rightchild] && s->val[rightchild] > s->val[pos])
          { swap(&s->val[rightchild],&s->val[pos]);
            return shift_down(s,rightchild);}
        else if (s->val[leftchild] > s->val[pos]){
            swap(&s->val[leftchild],&s->val[pos]);
            return shift_down(s,leftchild);}
    }
    else if (leftchild < s->quantity){
        if (s->val[leftchild] > s->val[pos]) {swap(&s->val[leftchild],&s->val[pos]);return shift_down(s,leftchild);}
    }
}

Подскажите что можно сделать с функцией?
  • Вопрос задан
  • 66 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы