Добавил:
Hist
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Программы c++ (сортировка, хэширование) / 3 / old1 / hc
.cpp#include <iostream>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <limits>
#define N 20
#define MaxStrLen 7
#define Ns 8
using namespace std;
char st[N][MaxStrLen];
int ht[N], key;
int hash_calc_sv2(char x[])
{
int StringLength,HashKey,i,tmp;
StringLength=strlen(x);
HashKey=0;
if (StringLength%2==0) //Чётный случай
{
for (i=0; i<StringLength; i=i+2)
{
tmp=x[i];
tmp=tmp*1000;
tmp=tmp+x[i+1];
HashKey=HashKey+tmp;
}
}
if (StringLength%2!=0) //Нечётный случай
{
for (i=1; i<StringLength; i=i+2)
{
tmp=x[i];
tmp=tmp*1000;
tmp=tmp+x[i+1];
HashKey=HashKey+tmp;
}
HashKey=HashKey+x[0];
}
return (HashKey);
}
int hash_calc(char x[])
{
int StringLength,HashKey,i;
StringLength=strlen(x);
HashKey=0;
for (i=0; i<=StringLength; i++) {HashKey=HashKey+x[i];}
return (HashKey);
}
int main(void)
{
strcpy(st[0],"asfx");
//key=hash_calc_sv2(st[0])%20;
key=hash_calc(st[0])%19;
cout<<key;
}
Соседние файлы в папке old1