哈希表C++实现--hash_table

本文详细介绍了如何使用C++实现哈希表,包括关键的hash_table.h头文件内容,以及可能涉及的数据结构和算法。通过阅读,读者可以深入理解哈希表在C++中的实现原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1、hash_table.h

#include <iostream>
  3 #include <string>
  4 #include <string.h>
  5 #include <vector>
  6 #include <stdio.h>
  7 using namespace std;
  8 
  9 struct table_node
 10 {
 11     int _key;
 12     string _value;
 13     struct table_node *next;
 14     table_node(const int key,const string &value)
 15         :_key(key),_value(value),next(NULL)
 16     {}
 17 };
 18 
 19 
 20 class hash_table
 21 {
 22     private:
 23         vector<table_node*> vector_node;
 24         size_t size;
 25     private:
 26         size_t fun_index(const int key)
 27         {
 28             return key % vector_node.size();
 29         }
 30         size_t get_size()
 31         {
 32             const int len=10;
 33             static size_t arr[len]={53,97,193,389,769,1543,3079,6151,12289,24593};
 34             static int i=0;
 35             return arr[i++];
 36         }
 37         vo
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值