I have an array of students with their First and Last Name
std::string students[5] = {
"Michael, Fred", "Shane, Lewis", "James, Fred", "Dan, Hot", "Sam, Lewis", "James, Lewis"};
I have converted the following to the linked list in the code shown below.
I want to cout last name of the students but if its same last name to be printed once
so the console should look like
last name 1 = fred,
last name 2 = lewis,
last name 3 = hot,
I am not sure on how to compare the last names so any help would be great
Thank you
What I have tried:
class node {
string FirstName;
string LastName;
node* nextStudent = nullptr;
node* nextSameLastName = nullptr;
};
node* find_student(node* start, std::string stu)
{
if (start == nullptr)
{
return nullptr;
}
if (student->LastName == stu)
{
return start;
}return find_student(start->nextStudent, stu);
}
void list_Student(node* n, node** r)
{
if (*r == nullptr)
{
*r = n;
return;
}
node* N = find_student(*r, n->LastName);
if (N == nulptr)
{
node* t = *r;
*r = n;
n->nextStudent = t;
}
else
{
node* t = N->nextSameLastName;
N->nextSameLastName = n;
n->nextSameLastName = t;
}
}
node* r = nullptr;
bool list(node** r, std::string students[], int num)
{
for (int i = 0; i < num; i++)
{
std::string stu = students[i];
std::string str = "";
node* n = new node();
for (char ch : str)
{
if (ch != ',')
{
str = str + c;
}
else
{
if (n->FirstName == "")
{
n->FirstName = str;
str = "";
}
else
{
n->LastName = str;
str = "";
}
}
}
list_student(n, r);
}
void samelastname(node* r)
{
}