首页 > 其他分享 >自定义比较 PersonT

自定义比较 PersonT

时间:2023-02-18 12:14:22浏览次数:35  
标签:p2 p1 自定义 int double numTemp PersonT DY 比较

class PersonT
{
public:
PersonT(double D0, double D1, double D2, string strNUMBER, double DX, double DY, double DZ, double DTAG)
{
this->M_D0 = D0;
this->M_D1 = D1;
this->M_D2 = D2;
this->strNUMBER = strNUMBER;
this->M_DX = DX;
this->M_DY = DY;
this->M_DZ = DZ;
this->M_DTAG = DTAG;


//this->m_strName = strName;
//this->m_iAge = iAge;
//this->m_iHeight = iHeight;
}


double M_D0;
double M_D1;
double M_D2;
string strNUMBER;
double M_DX;
double M_DY;
double M_DZ;
double M_DTAG;

//string m_strName; // 姓名
//int m_iAge; // 年龄
//int m_iHeight; // 身高
};


// 打印列表
void PrintList(list<PersonT>& pList)
{

UF_initialize();

UF_UI_open_listing_window();
char msg[256];


for (list<PersonT>::iterator it = pList.begin(); it != pList.end(); it++)
{
PersonT pIt = *it;

sprintf(msg, "%.2f, %.2f, %.2f, %s, %.2f, %.2f, %.2f, %.0f", pIt.M_D0, pIt.M_D1, pIt.M_D2, pIt.strNUMBER.c_str(), pIt.M_DX, pIt.M_DY, pIt.M_DZ, pIt.M_DTAG);

UF_UI_write_listing_window(msg);
UF_UI_write_listing_window("\n");

}

UF_terminate();

}

 

 

//bool comparePerson(PersonT &p1, PersonT &p2)// 比较函数
//{
// if (p1.M_D1 == p2.M_D1) //如果第一个数相等,比较第二个数
// {
// if (p1.M_DY == p2.M_DY)//如果第二个数相等,比较第三个数
// {
// return p1.M_DX < p2.M_DX;
// }
// return p1.M_DY < p2.M_DY;
// }
// return p1.M_D1 < p2.M_D1; //比较第一个数
//}

 

bool comparePerson(PersonT &p1, PersonT &p2)// 比较函数
{
int numTemp = 10000;

if (int(p1.M_D1*numTemp) == int(p2.M_D1*numTemp)) //如果第一个数相等,比较第二个数
{
if (int(p1.M_D2*numTemp) == int(p2.M_D2*numTemp))//如果第二个数相等,比较第三个数
{
if (int(p1.M_DY*numTemp) == int(p2.M_DY*numTemp))//如果第三个数相等,比较第四个数
{
return int(p1.M_DX*numTemp) < int(p2.M_DX*numTemp);
}
return int(p1.M_DY*numTemp) < int(p2.M_DY*numTemp);//比较第三个数
}
return int(p1.M_D2*numTemp) < int(p2.M_D2*numTemp); //比较第二个数
}
return int(p1.M_D1*numTemp) < int(p2.M_D1*numTemp); //比较第一个数
}

标签:p2,p1,自定义,int,double,numTemp,PersonT,DY,比较
From: https://www.cnblogs.com/firetuo/p/17132295.html

相关文章