This code is from a example in Jumping Into C++ and I understand the example. But it is a practice problem that is to write a program to remove an element from a linked list; the remove function should take just the element to be removed.
If I got this right I will create a pointer that points to the first SHIP (getNewEnemy) and the other one will not be printed out.Code:#include <iostream>
using namespace std;
struct EnemySpaceShip
{
int x_coordinate;
int y_coordinate;
int weapon_power;
EnemySpaceShip *p_next_enemy;
};
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 = NULL;
return p_ship;
}
void updateShip(EnemySpaceShip *p_ship)
{
p_ship->x_coordinate += 10;
p_ship->y_coordinate += 10;
p_ship->weapon_power += 20;
cout << "X: " << p_ship->x_coordinate << endl;
cout << "Y: " << p_ship->y_coordinate << endl;
cout << "Weapon Power: " << p_ship->weapon_power << endl;
}
int main()
{
EnemySpaceShip *getShip = getNewEnemy();
updateShip(getShip);
return 0;
}