I'm trying to figure out how to create a linked list where each element of that list contains its own linked list. The first list is a list of teams and the second is a list of players on that team so it should output something like this:
Team1: player1, player2
Team2: player1, player2, player3
etc...
I'm struggling to figure out how to do this though. My teacher tried to help me get started by making the Team and Player classes and then a Playerlinklist, Teamlinklist, Playernode, and teamnode classes
Here is the playerlinklist and playernode classes for an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#ifndef PLAYERLKLIST_H
#define PLAYERLKLIST_H
#include "PlayerNode.h"
class PlkList
{
private:
PNode *pLP;
public:
PlkList();
void insert(Player playerObj1);
void printPL();
};
PlkList::PlkList()
{
pLP = NULL;
}
void PlkList::insert(Player playerObj1)
{
PNode *p = new PNode;
p->PData = playerObj1;
p->next = pLP;
pLP = p;
}
void PlkList::printPL()
{
PNode *p = pLP;
if (pLP == NULL)
{
cout << "The list is empty" << endl;
}
else
while (p != NULL)
{
cout << "[" << p->PData.getName() << ", " << p->PData.getNumber() << "] ->";
p = p->next;
}
}
#endif
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#ifndef PLAYERNODE_H
#define PLAYERNODE_H
#include "Playerinfo.h"
class PNode
{
public:
Player PData;
PNode *next;
PNode();
};
PNode::PNode()
{
next = NULL;
}
|
The team lklist and node classes are essentially the same except using TNode, pLT, and t instead of PNode, pLP, and p.
How do I go about connecting these though so that an elements in team points to a list of players?