12.9随笔
这里是12.9随笔。
代码留档:#include <stdio.h>
include <stdlib.h>
define MAX 1024
typedef struct Hash_{
int HashList[MAX];
int Length;
}Hash, *PHash;
int main(){
int n, p;
scanf("%d %d",&n, &p);
PHash NewHash = (Hash)calloc(1, sizeof(Hash));
for(int i = 0; i < p; i++){
NewHash->HashList[i] = -1001;
}
NewHash->Length = p;
int value, value0, flag;
for(int i = 0; i < n; i++){
scanf("%d", &value);
value0 = value % p;
/重复数放在一个位置/
flag = 1;
for(int j = 0; j < p; j++){
if(value == NewHash->HashList[j]){
flag = 0;
printf("%d", j);
}
}
if(flag == 0){
if(i != n - 1) printf(" ");
continue;
}
/******************************************/
while(NewHash->HashList[value0] != -1001){ //若当前位置不为空,进行线性探测
value0++;
if(value0 >= p)
value0 = 0;
}
NewHash->HashList[value0] = value;
printf("%d", value0);
if(i != n - 1){
printf(" ");
}
}
return 0;
}