以下是引用TonyDeng在2012-2-18 11:29:44的发言:
關於複雜度,給你舉一個例子,看如下兩個版本的代碼:
void * memchr(void * pv, unsigned char ch, size_t size)
{
unsigned char * pch = (unsigned char * )pv;
unsigned char * pchEnd = pch + size;
while (pch < pchEnd && *pch != ch) pch++;
return ((pch < pchEnd) ? pch : NULL);
}
void * memchr(void * pv, unsigned char ch, size_t size)
{
unsigned char * pch = (unsigned char * )pv;
unsigned char * pchEnd = pch + size;
while (pch < pchEnd)
{
if (*pch == ch) return (pch);
pch++;
}
return (NULL);
}
你覺得哪個較好?
要我选是第二个,简洁明了。。。。