Can somebody help me with a function `f` such that it extract all sub expressions (i.e. looking down the expression tree) from any expression given to it and also a list of heads it encounters as it moves down the expression tree.

For example, `f@(Sin[Log[Cos[a], Tan[Log[a, b]]]] // Inactivate)` gives `{
{
Inactive[Sin][Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]]],
Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]],
Inactive[Cos][a],
Inactive[Tan][Inactive[Log][a, b]],
a,
Inactive[Log][a,b],
a,
b
},
{
Inactive[Sin],
Inactive[Log],
Inactive[Cos],
Inactive[Tan],
Inactive[Log]
}
}`

Note: order of occurrence and duplicacy must be maintained

Explanation of Order of sub expressions (also the order in which heads are removed to move to the next sub expression)

first the full expression

[![enter image description here][1]][1]


next the expression starting from the second level (Head `Inactive[Sin]` is removed)


[![enter image description here][2]][2]


next the two expressions at level 3 (Head `Inactive[Log]` is removed)


[![enter image description here][3]][3]


[![enter image description here][4]][4]


next the two expression at level 4 from left to right (next the Head `Inactive[Cos]` and then `Inactive[Tan]` is removed moving from left to right)


[![enter image description here][5]][5]


[![enter image description here][6]][6]


finally the two expressions at the last level from left to right (lastly the Head `Inactive[Log]` is removed to arrive at the last level)


[![enter image description here][7]][7]


[![enter image description here][8]][8]

This is the general order i want to have for sub expressions and the also the order of removal of Heads.

  [1]: https://i.sstatic.net/tXr02.png
  [2]: https://i.sstatic.net/ExZ1w.png
  [3]: https://i.sstatic.net/bU7PG.png
  [4]: https://i.sstatic.net/eO7cT.png
  [5]: https://i.sstatic.net/utchp.png
  [6]: https://i.sstatic.net/MueLm.png
  [7]: https://i.sstatic.net/JRkVx.png
  [8]: https://i.sstatic.net/Dj5vn.png