我如何过滤双向链表?

问题描述 投票:0回答:1
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;

我正在尝试根据评分来搜索导师。由于评分可以重复,因此通过搜索可以返回多个导师。但是我只有一位导师。如何获得基于评分的多位导师?

c++ doubly-linked-list
1个回答
0
投票

只需从循环中删除break;

© www.soinside.com 2019 - 2024. All rights reserved.