BOOL Option::BinarySearch(const char *szKey) { int left; int right; int mid; MString str; /** * 没有配置needlist,表示不进行查找控制 * 虽然和needlist的含义有点背,主要为兼容考虑的. */ if(m_nNeedCnt == 0) return TRUE; str.Empty(); str = szKey; if(m_IsCase) { str.Lower(); } left = 0; right = m_nNeedCnt - 1; while(left <= right) { mid = (left + right) / 2; if(strcmp(m_stNeedArray[mid].szValue, str.c_str()) == 0) return TRUE; else if(strcmp(m_stNeedArray[mid].szValue, str.c_str()) < 0) left = mid + 1; else right= mid - 1; } return FALSE; }
void Option::BubbleSort() { /** * strcmp function * str1 > str2 @return >0 * str1 < str2 @return <0 */ int i, j; char szTemp[32]; MString str; if(m_IsCase) { for(i = 0; i < m_nNeedCnt; i++) { str.Empty(); str = m_stNeedArray[i].szValue; str.Lower(); strcpy(m_stNeedArray[i].szValue, str.c_str()); } } for(i = 0; i < m_nNeedCnt - 1; i++) { for(j = i + 1; j < m_nNeedCnt; j++) { if(strcmp(m_stNeedArray[i].szValue, m_stNeedArray[j].szValue) > 0) { memset(szTemp, 0, sizeof(szTemp)); strncpy(szTemp, m_stNeedArray[i].szValue, sizeof(szTemp)); strncpy(m_stNeedArray[i].szValue, m_stNeedArray[j].szValue, sizeof(m_stNeedArray[i].szValue)); strncpy(m_stNeedArray[j].szValue, szTemp, sizeof(m_stNeedArray[j].szValue)); } } } }