Hardware interview practice
Stable sort transaction handles
Sort a queue of transaction handles by address while preserving the original order of equal-address transactions.
Reviewed example
Work through one case
Input
transactions in arrival order=[(addr=0x20,A),(addr=0x10,B),(addr=0x20,C)]Expected output
sorted handles=[B,A,C]Address 0x10 sorts first, while the original positions keep A before C for the equal 0x20 keys; the same handles are retained.
What to cover
Requirements
- Do not clone or replace the transaction objects.
- Preserve input order when addresses are equal.
- Use the original position as an explicit tie-breaker.
