The inheritance is based on the presence, as has been said before by brifbates.
If the primary son dies before the current king, his oldest brother will inherit, as long as the primary son hasn't had a son until then.
If he had a son until then, his son will inherit before his own uncles. The next in line then would be his sister.
To look at it in a slightly different manner...
Your primary heirs are your descendants followed by your siblings, then finally your parents, as Aardvark said, Agnatic-Cognatic is male before female so the list of descendants is filled males then females starting with the firstborn son and any sons they have and so on. In the case where the firstborn son lives and inherits his brothers get pushed back in line behind all of his descendants as they are now siblings instead of descendants; thus the daughter will now be ahead of her uncles in line but would still be after any younger brothers she might have.
The current crown laws in the UK are pure primo without regard to gender, which is not one of the options available in game. The laws were changed to that system well after the CK time frame.