/使用迭代器進行字典順序比較
template <typename Iterator>
bool Compare(Iterator first1, Iterator last1, Iterator first2, Iterator last2)
{
for (; first1 != last1 && first2 != last2; ++ first1, ++ first2)
{
if (*first1 < *first2)return true;
if (*first2 < *first1)return false;
}
// 判斷是否第一個串長度小於第二個串長度
return first1 == last1 && first2 != last2;
}
// 字符串比較,str1 < str2 返回true
bool StrCmp(const char * str1, const char * str2)
{
assert(NULL != str1);
assert(NULL != str2);
return Compare (str1 , str1 + strlen(str1), str2, str2 + strlen(str2));
}