Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I only can add code in void order_two_players(player_t* player1_p, player_t* pla

ID: 3742298 • Letter: I

Question

I only can add code in void order_two_players(player_t* player1_p, player_t* player2_p)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void order_two_players(player_t* player1_p, player_t* player2_p)
{

/*
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.
*/


}

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void order_two_players(player_t** player1_p, player_t** player2_p)

{

    /*

        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.

    */

    // if *player1_p is older than the *player2_p

    if( (*player1_p)->age > (*player2_p)->age )

    {

        player_t **temp = player1_p;

        player1_p = player2_p;

        player2_p = temp;

    }

}

int main()

{

    player_t* player1_p;

    player_t* player2_p;

   

    // pass by reference

    order_two_players( &player1_p , &player2_p );

}