Hey man, really late to the party and hope you aren't still stuck on this question just decided to reply as I have been stuck on this for the best part of a week but I now know how to do this. You need to get question properties and groups for this to work. First populate an array with only parent questions and sort the parent questions by group_order - which you can link by using the questions gid property matching in your array of groups. Then sort the sub questions based on their respective question_order but make them separated by parent_qid. Finally, put the sub questions immediately after their respective parents in your now sorted array.
For some reason they seem to sort questions by a mixture of qid and parents but this rarely works as the qid is the order questions were created in and not necessarily the final order the user wanted.