Let's consider a situation where two heroes fighting each other have all 7 stacks with units of the same speed. Then, the first stack of the attacking hero will go first, the second stack of the defending hero will go second, the third stack of the attacking hero will go third, the fourth stack of the defending hero will go fourth... In the second round, the top stacks go first again, but first for the defending hero, then for the attacking hero, that is, the first stack of the defending hero goes first, the second stack of the attacking hero goes second, the third stack of the defending hero goes third, the fourth stack of the attacking hero goes fourth... In the third round, the order will be the same as in the first, in the fourth - as in the second, and so on... I think that's how it works.
This is when the units don't skip their turns. But what if someone waits or goes into defense – what changes occur in the turn order?
Added after 22 hours 6 minutes
Let's take a specific example. Suppose two heroes are fighting. The attacker has champions and royal griffins in the first and fifth stacks, and the defender has death knights and vampire lords in the third and fourth stacks. All of the listed units have the same speed - 9. Who will go after whom? Does the fact that all seven stacks are filled matter?