Welcome

首页 / 软件开发 / 数据结构与算法 / 算法系列(七) 爱因斯坦的思考题(下)

算法系列(七) 爱因斯坦的思考题(下)2014-04-30 csdn博客 吹泡泡的小猫CheckGroupRelation()函数需要根据当前组group的位置进行适当的处理,如果当前组是第一个 组或最后一个组,则group的相邻组只有一个,就是最靠近group的组,其它情况下group的相邻组都是 两个。CheckGroupRelation()函数的实现如下:

162 bool CheckGroupRelation(GROUP *groups, int groupIdx, ITEM_TYPE type, int value)163 {164 if(groupIdx == 0)165 {166 if(GetGroupItemValue(&groups[groupIdx + 1], type) != value)167 {168 return false;169 }170 }171 else if(groupIdx == (GROUPS_COUNT - 1))172 {173 if(GetGroupItemValue(&groups[groupIdx - 1], type) != value)174 {175 return false;176 }177 }178 else 179 {180 if( (GetGroupItemValue(&groups[groupIdx - 1], type) != value)181 && (GetGroupItemValue(&groups[groupIdx + 1], type) != value) )182 {183 return false;184 }185 }186 187 return true;188 }