您的位置:首页 > 其它

2015年8月20日21:03:18 firstNotRepeatingChar 哈希表实现O(n)

2015-08-20 21:01 363 查看
<pre name="code" class="cpp">//for a char datetyp
4000
e,a 256 array hashtable .
//looking for the first ,so wo should keep the sort
char FirstNotRepeatingChar(char* pString)
{
if(pString == NULL)
return '\0';

const int tableSize = 256;
unsigned int hashTable[tableSize];
for(unsigned int i = 0; i<tableSize; ++ i)
hashTable[i] = 0;

char* pHashKey = pString;
while(*(pHashKey) != '\0')
hashTable[*(pHashKey++)] ++;

pHashKey = pString;
while(*pHashKey != '\0')
{
if(hashTable[*pHashKey] == 1)
return *pHashKey;

pHashKey++;
}

return '\0';
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: