首页 > 其他 > 详细

哈希表---线性探测再散列(hash)

时间:2014-12-04 22:57:52      阅读:403      评论:0      收藏:0      [点我收藏+]
//哈希表---线性探测再散列

#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#define m 10000
#define NULLkey -1


using namespace std;

int HashTable[m];

int Hash_search( int k)
{
    int p0, pi;
    p0=hash(k); //函数运算值
    if(HashTable[p0]== NULLkey )
    {
        return -1;
    }
    else if(HashTable[p0]==k )
    {
        return p0;
    }
    else //用线性探测再散列 解决冲突
    {
        for(i=0; i<=m-1; i++)
        {
            pi=(p0+i)%m;
            if(HashTable[pi]==NULLkey )
            {
                return -1;
            }
            else if(HashTable[pi]==k )
            {
                return pi;
            }
        }
        return -1;
    }
}

 

哈希表---线性探测再散列(hash)

原文:http://www.cnblogs.com/yspworld/p/4143913.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!