The book I'm reading, Introduction to Data Structures with Linked Lists (Presentation 21), has 2 examples of linked lists. Here is the first one:
EnemySpaceShip* getNewEnemy ()
{
EnemySpaceShip* p_ship = new EnemySpaceShip;
p_ship->x_coordinate = 0;
p_ship->y_coordinate = 0;
p_ship->weapon_power = 20;
p_ship->p_next_enemy = p_enemies;
p_enemies = p_ship;
return p_ship;
}
The second example of linked lists is this one:
EnemySpaceShip* addNewEnemyToList (EnemySpaceShip* p_list)
{
EnemySpaceShip* p_ship = new EnemySpaceShip;
p_ship->x_coordinate = 0;
p_ship->y_coordinate = 0;
p_ship->weapon_power = 20;
p_ship->p_next_enemy = p_list;
return p_ship;
}
Then the book writes this:
Notice that this function differs from
getNewEnemy
because it returns a pointer to the list, rather than the new enemy.
What I don't understand is what he means by the "second function returns a pointer to the list" and "the first function returns the new enemy". I thought that they have both created a new enemy called p_ship
(which is both a pointer and a new enemy) and returned it. What is meant by this statement?