如何过滤双向链表?
How do I filter a doubly linked list?
struct Node
{
int tutorID;
string tutorName;
int day_join;
int month_join;
int year_join;
int day_ter;
int month_ter;
int year_ter;
int hourly_pay_rate;
int phone;
string address;
int centerCode;
string centerName;
int subjectCode;
string subjectName;
int rating;
struct Node* prev;
struct Node* next;
};
cout << "Enter Rating:" << endl;
cin >> rating;
while (current != NULL)
{
if (current->rating == rating)
{
cout << "Tutor ID:" << current->tutorID << endl;
cout << "Tutor Name:" << current->tutorName << endl;
cout << "Date Joined:" << current->day_join << "/" << current->month_join << "/" << current->year_join << endl;
cout << "Date Terminated:" << current->day_ter << "/" << current->month_ter << "/" << current->year_ter << endl;
cout << "Hourly Pay Rate:" << current->hourly_pay_rate << endl;
cout << "Phone:" << current->phone << endl;
cout << "Address:" << current->address << endl;
cout << "Center Code:" << current->centerCode << endl;
cout << "Center Name:" << current->centerName << endl;
cout << "Subject Code:" << current->subjectCode << endl;
cout << "Subject Name:" << current->subjectName << endl;
cout << "Rating:" << current->rating << endl;
current = current->next;
flag = 1; /*tutor details found*/
break;
}
current = current->next; /*move to one node to another*/
}
if (flag == 0) /*if still no match found*/
cout << "Not found" << endl;
我正在尝试根据评分搜索导师。由于评分可以重复,搜索它会 return 多个导师。但我只有 1 位导师。如何根据评分获得多个导师?
只需从循环中删除 break;
。
struct Node
{
int tutorID;
string tutorName;
int day_join;
int month_join;
int year_join;
int day_ter;
int month_ter;
int year_ter;
int hourly_pay_rate;
int phone;
string address;
int centerCode;
string centerName;
int subjectCode;
string subjectName;
int rating;
struct Node* prev;
struct Node* next;
};
cout << "Enter Rating:" << endl;
cin >> rating;
while (current != NULL)
{
if (current->rating == rating)
{
cout << "Tutor ID:" << current->tutorID << endl;
cout << "Tutor Name:" << current->tutorName << endl;
cout << "Date Joined:" << current->day_join << "/" << current->month_join << "/" << current->year_join << endl;
cout << "Date Terminated:" << current->day_ter << "/" << current->month_ter << "/" << current->year_ter << endl;
cout << "Hourly Pay Rate:" << current->hourly_pay_rate << endl;
cout << "Phone:" << current->phone << endl;
cout << "Address:" << current->address << endl;
cout << "Center Code:" << current->centerCode << endl;
cout << "Center Name:" << current->centerName << endl;
cout << "Subject Code:" << current->subjectCode << endl;
cout << "Subject Name:" << current->subjectName << endl;
cout << "Rating:" << current->rating << endl;
current = current->next;
flag = 1; /*tutor details found*/
break;
}
current = current->next; /*move to one node to another*/
}
if (flag == 0) /*if still no match found*/
cout << "Not found" << endl;
我正在尝试根据评分搜索导师。由于评分可以重复,搜索它会 return 多个导师。但我只有 1 位导师。如何根据评分获得多个导师?
只需从循环中删除 break;
。