ProgrammingModerate
After removing duplicate keys from a sorted array of records with the two-index method (keep a[w] when its key differs from the last kept key), how many records remain for keys 2, 2, 5, 5, 5, 9?
- A. 2
- B. 4
- C. 6
- D. 3
Correct answer: D. 3
The distinct keys are 2, 5 and 9, so three records remain after the two-index pass.
More C Programming questions
- Bubble sort on the records of 4 keys {4, 3, 2, 1} with a swap count: how many swaps are made?
- A struct array holds records with an int key; the program calls qsort with the comparator (int)(a->key - b->key) for keys near INTMAX and…
- A bsearch call uses a key of type int but the array holds struct records with an int field. What is the correct way to compare?
- Which comparator for qsort on int array is correct for ALL int values (no overflow, no wrong sign)?
- int m[3][4]; int f = &m[0][0]; Which expression refers to the same element as m[2][1]?
- int m[3][4]; What is sizeof(m) / sizeof(m[0][0])?