Exchange Sort (2)
- Extend your previous program about
Exchange Sort
so that it will input the name, height, and weight of 8 players.
For example,
LeBron-James 203 109
Bolt 196 94
D-Bryant 188 100
C-Johnson 197 107
Ibaka 208 111
A-Peterson 185 98
J-Jones 193 93
Phelps 192 88
- Sort them by height. Print the result.
- Hint: In addition to the arrays name[], height[], weight[],
create a "pointer" array index[] which points to those 8 players, and
short this index[] array according to height[index[i]].
- Then sort them by weight, and print the result.
- Finally, print the original input so that you can compare the
results.
- When you print out player names, please right-justify them.
The output may look as follows.
===============
Sort by height:
===============
Ibaka 208 111
LeBron-James 203 109
C-Johnson 197 107
Bolt 196 94
J-Jones 193 93
Phelps 192 88
D-Bryant 188 100
A-Peterson 185 98
===============
Sort by weight:
===============
Ibaka 208 111
LeBron-James 203 109
C-Johnson 197 107
D-Bryant 188 100
A-Peterson 185 98
Bolt 196 94
J-Jones 193 93
Phelps 192 88
=====================
Original input order:
=====================
LeBron-James 203 109
Bolt 196 94
D-Bryant 188 100
C-Johnson 197 107
Ibaka 208 111
A-Peterson 185 98
J-Jones 193 93
Phelps 192 88