Practice
Remove Duplicates
Write a function with the header
int removeDuplicates(char name[][31], int age[], int *n) |
that removes all duplicate records from a table.
The table consists of *n records
and each record consists of a null-terminated string containing
a person’s name and an int containing
their age. *n
holds the number of records in the table when
removeDuplicates() is called and the number
of records in the updated table upon return from
removeDuplicates(). A duplicate record
is a record that has the
same name as another record, but not necessarily the
same age. When removing a duplicate record,
your function keeps the record with the lower index and discards the
record with the higher index.
Your function returns the
total number of records removed.
Each name in the array of names is unique upon return from
removeDuplicates().
Example:
Before call to removeDuplicates
name[ ][] age[ ] *n
-------------------------------
Homer 45 6
Marge 22
Homer 42
Bart 14
Marge 21
Lisa 8 |
After call to removeDuplicates
name[ ][] age[ ] *n
----------------------
Homer 45 4
Marge 22
Bart 14
Lisa 8
|
|