You need two linked lists, one for the Employees and one for the Skills. Although the number of skills is specified in the input file, you don't need to store it. I'll add a constructor, as it'll make things easier later on.
A node in the Skills list might look like:
1 2 3 4 5 6 7
|
struct SkillNode {
SkillNode() : next(nullptr), experience(0) {}
SkillNode* next;
std::string name;
unsigned experience;
};
|
And a node in the Employee list might look like:
1 2 3 4 5 6 7
|
struct EmployeeNode {
EmployeeNode() : next(nullptr), skills(nullptr) {}
EmployeeNode* next;
std::string name;
SkillNode* skills;
};
|
One of the things you might want to do is add and entry from you input data. So first you need to wrap all those nodes in a single entity that you can work with.
1 2 3 4 5 6
|
class Employees {
EmployeeNode* head;
public:
Employees() : head(nullptr) {}
};
|
Ok, back to what we wanna do with it, add entry from your input line:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void Employee::add(std::string line) {
EmployeeNode* empNode = new EmployeeNode;
// make an input stream from the line so we can parse it
std::istringstream is(line);
int n;
is >> empNode->name >> n;
for (int i = 0; i < n; ++i) {
SkillsNode* skillsNode = new SkillsNode;
is >> skillsNode->name >> skillsNode->experience;
skillsNode->next = empNode->skills;
empNode->skills = skillsNode;
}
// add the newly created EmployeeNode to the head of the list.
empNode->next = head;
head = empNode;
}
|
You'd add methods for the things you want to do with Employees to that class. Don't expose the program to nodes, that's an implementation detail.
Also, I've just typed this code into the page, I haven't tried to compile it. But I'm just demonstrating how you may consider doing it. So it may not compile, especially as I haven't shown the headers you'd need to include.