List with a Struct in C++

55 views Asked by At

I have a "Squadron" class which has several "Ships" in a list. This is an exercise and I'm not allowed to use STL containers.

The aim is to keep things as simple as possible and therefore not to implement a complicated class (like a complete LinkedList class), which is why I've gone for the idea of a "struct" with pointers to "node" and "next".

However, I don't really know how to go about it, so I started with an idea like this:

 struct ShipNode {
 Ship* node
 Ship* next

Constructor
Destructor
}

struct ShipListNode {
 Ship* head
     
Constructor
Destructor

AddShip
RemoveShip
}

Does this sound like a good idea or do you have any others? And does my initial implementation seem logical?

I'm also wondering how I'm going to manage the nodes in my list. I think I'd need a pointer to an iterator in "ShipListNode", don't you think? As for "head", I wonder if it shouldn't be static. Since I have a list by Squadron class only, that wouldn't be a problem or would it?

Thanks to anyone who takes the time to reply, and have a nice day!

0

There are 0 answers