void order_two_players(player_t* player1_p, player_t* player2_p) { player_t *tmp
ID: 3744015 • Letter: V
Question
void order_two_players(player_t* player1_p, player_t* player2_p)
{
player_t *tmp = player1_p;
player1_p = player2_p;
player1_p = tmp;
/*
This function compares two players. If *player1_p is older than the *player2_p,
swap them. In all other cases, do not swap them.
Inputs:
player1_p - memory location of the first player
player2_p - memory location of the second player
Post:
After the function has been called, the age of *player1_p is always less than
or equal to *player2_p age.
Correct output:
player1: player - age:32 wickets:300
player2: player - age:22 wickets:070
after order_two_players
player1: player - age:22 wickets:070
player2: player - age:32 wickets:300
*/
}
How I can fix it?
Explanation / Answer
void order_two_players(player_t* player1_p, player_t* player2_p)
{
if(player1_p <=player2_p)
{
//print information as it is.
}
else
{
player_t *tmp = player1_p;
player1_p = player2_p;
player1_p = tmp;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.