///
// Find the first char which appears only once in a string
// Input: pString - the string
// Output: the first not repeating char if the string has, otherwise 0
///
char hash(char * str) //对 hash表的用法!非常经典!!!!
{
const int tablesize=256;
unsignedint hashtable [256];
if(!str)
return NULL;
for(int i=0;i<tablesize;i++)
{
hashtable[i]=0;
}
char * p=str;
while(*p!='\0')
hashtable[*(p++)]++; //此语句是核心!!!
p=str;
while(*p!='\0')
if(hashtable[*(p++)]==1)
{
return *(--p);
}
return 0;
}