How to get hirarchy of all objects dynamically through schema code in salesforce
I have code like below.

set<string> strForRelatedObjects = new set<string>();

      
      Schema.SObjectType objectType = schema.getGlobalDescribe().get('child__c');
        for(Schema.SobjectField strFld: objectType.getDescribe().fields.getMap().Values()){
            
            if(strFld.getDescribe().getType() == Schema.DisplayType.REFERENCE){
                strForRelatedObjects.add(string.valueof(strFld.getDescribe().getReferenceTo()).substringBetween('(',')')); 
                
             }
        }.

 I want to fetch all parent object to object(Overall hirarchy).and above code should in position to get all the related objects to to objects i want to fetch