Sooey County is about to have its annual Big Pig Contest. Because the sheriffs son, Wilbur, is
Question:
Sooey County is about to have its annual Big Pig Contest. Because the sheriff’s son, Wilbur, is majoring in computer science, the county hires him to computerize the Big Pig judging. Each pig’s name (string) and weight (integer) are to be read in from the keyboard. The county expects 500 entries this year.
The output needed is a listing of the ten heaviest pigs, sorted from biggest to smallest. Because Wilbur has just learned some sorting methods in school, he feels up to the task of writing this “porkgram.”
He writes a program to read all the entries into an array of records, then uses a selection sort to put the entire array in order based on the pigWeight member. He then prints the ten largest values from the array.
Can you think of a more efficient way to write this program? If so, write the algorithm.
Step by Step Answer:
C++ Plus Data Structures
ISBN: 9781284089189
6th Edition
Authors: Nell Dale, Chip Weems, Tim Richards