ProgrammingHard
Records are sorted by name length first, then alphabetically, using qsort with a comparator on strlen and strcmp. Input names: bob, al, carol, dan. What is the output order?
- A. al bob dan carol
- B. al dan bob carol
- C. bob al dan carol
- D. al bob carol dan
Correct answer: A. al bob dan carol
Shorter names come first. The two-letter name al is first, then the three-letter names bob and dan in alphabetical order, then carol.
More C Programming questions
- Records (x,5), (y,2), (z,5), (w,2), (v,9) are sorted by key with a stable sort, ascending. What is the order of names?
- The same five records are sorted by key with a stable sort in descending order. What is the order of names?
- In records (x,5), (y,2), (z,5), (w,2), (v,9), the index of the minimum key, choosing the first when there are ties, is which index?
- Records A (key 9), B (key 3), C (key 9) are scanned with if (r.key >= best.key) best = r; starting from the first record. Which record is…
- Records (x,5), (y,2), (z,5), (w,2), (v,9) are reduced to one record per key by keeping the last record seen for each key, then sorted by…
- Insertion sort (shift larger elements right, then place the key) is applied to {4, 1, 3, 2}. How many element shifts happen in total?