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

来源:互联网 发布:转换成淘宝客链接 编辑:程序博客网 时间:2024/06/05 03:58
<pre name="code" class="cpp">//for a char datetype,a 256 array hashtable .//looking for the first ,so wo should keep the sortchar 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';} 


                                             
0 0
原创粉丝点击