Hi,
I have defined a structure as
I have 2 different lists containing the report rows structure.Code:typedef struct ps_report_rows
{
std::string cp_item_id;
std::string cp_object_string;
std::string mfg_object_string;
std::string mor_item_id;
} report_row;
Some report rows in the two lists would be common and some unique. I want to find all the unique report rows that exist in objectList1 and store them in another list.Code:list<report_row> objectList1;
list<report_row> objectList2;
This is the code I have in mind
Does this code look good enough? Is there a more efficient way to achieve this?Code:list < report_row > ::iterator listIter1;
list < report_row > ::iterator listIter2;
bool isDuplicate = false;
list<report_row> finalList;
finalList.clear();
for (listIter1 = objectList1.begin(); listIter1 != objectList1.end() ; listIter1++)
{
report_row primaryRow = *listIter1;
for (listIter2 = objectList2.begin(); listIter2 != objectList2.end() ; listIter2++)
{
isDuplicate = false;
report_row secondaryRow = *listIter2;
check_if_duplicate_row(primaryRow, secondaryRow, isDuplicate);
if(isDuplicate == true)
break;
}
if(isDuplicate == false)
{
finalList.push_back(primaryRow);
}
}
void check_if_duplicate_row(report_row primaryRow, report_row secondaryRow, bool& isDuplicate)
{
if(primaryRow->cp_item_id!=secondaryRow->cp_item_id)
{
isDuplicate = false;
break;
}
if(primaryRow->cp_object_string!=secondaryRow->cp_object_string)
{
isDuplicate = false;
break;
}
if(primaryRow->mfg_object_string!=secondaryRow->mfg_object_string)
{
isDuplicate = false;
break;
}
if(primaryRow->mor_item_id!=secondaryRow->mor_item_id)
{
isDuplicate = false;
break;
}
isDuplicate = true;
}