【发布时间】:2019-03-19 18:52:35
【问题描述】:
我正在使用无符号类型的有序对typedef pair<unsigned, unsigned> OP;,以及有序对集合typedef set<OP> SOP;。
我的程序的最终目标是检查集合(关系)是否是等价关系。
我的问题:我已经设法检查一个集合是否是自反的,但目前我正在尝试检查该集合(关系)中的有序对是否是对称的。我目前已经构建了两个 for 循环来比较有序对,但在我的比较中遇到了死胡同。
我的代码:
for (auto it3 = sop.begin(); it3 != sop.end(); it3++) { // loop through each pair in set
for (auto it4 = sop.begin(); it4 != sop.end(); it4++) { // compare with other pairs
// make sure first and second items in pair are different
while (it3->first != it3->second) {
//If the case is that there is not an instance of
//symmetric relation return false
if (!((it3->first == it4->second) && (it3->second == it4->first))) {
return false;
}
}
}
}
【问题讨论】:
-
请在此处提供一个minimal reproducible example 以重现您的问题,并具体说明您的代码的意外行为(输入、实际输出、预期输出、您的调试工作)。
标签: c++ algorithm set relationship discrete-mathematics