#recursion logic

18 messages · Page 1 of 1 (latest)

crude prawn
#
// Task 6: Promote a staff to the same level as his original supervisor
Staff* Search_supervisor(Staff *staff_head, const unsigned int target_sid){
    if(staff_head==nullptr){
        return nullptr;
    }
    Staff *staff=nullptr;
    for(int i=0;i<staff_head->number_of_subordinate;i++){
        if(staff_head->subordinate[i]->sid==target_sid){
            staff=staff_head;
            return staff;
        }
    }
    for(int i=0;i<staff_head->number_of_subordinate;i++){
        staff=Search_supervisor(staff_head->subordinate[i],target_sid);
    }
    
    return staff;
}

anything wrong with the logic?
Tried debugging but i dont know whats wrong

ivory cedarBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

pure quarry
#

Is something not working?

zenith pawn
#

you're setting staff to every result

#

i assume you might want to only do that if what the function call returns isnt nullptr perhaps?

crude prawn
crude prawn
zenith pawn
crude prawn
#

Yep

#

Tysm

#

I’ll try it after I finish eating

zenith pawn
ivory cedarBOT
#

@crude prawn Has your question been resolved? If so, type !solved :)

crude prawn
#

it worked

#

tysm

#

!solved