[self hashAlgorithmMethod:@"hhaabccdeef"];
//ASCII码映射表算是某种哈希规则函数的直观呈现,通过该哈希函数表存储/查找,有效地提高效率。
//符号字母a对应着ASCII映射表中数据编码值97,数组索引97下标
//HASH算法
//2^8=256种编码组合
- (void)hashAlgorithmMethod:(NSString *)testStr {
char testCh[100];
memcpy(testCh,[testStr cStringUsingEncoding:NSUTF8StringEncoding], [testStr length]);
int list[256];//数组坑位中存储每个字符出现的次数
for (int i = 0; i < 256; i++) {
list[i] = 0;
}
//数组容器的底层采用的结构特征:链表结构
char *p = testCh;//p指针型变量;p++地址右移1个字节长度后下一个字节对应的新地址//p本身的栈中存储着第0号数据内容元素所在内存区的入口地址&0
char result = '\0';
while (*p != result) {
list[*(p++)]++;
}
p = testCh;
while (*p != result) {
if (list[*p] == 1) {
result = *p;
break;
}
p++;
}
printf("result:%c",result);
}
HASH算法
于 2020-10-29 11:43:28 首次发布