top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to implement Hash table in c/c++ ?

+2 votes
219 views
How to implement Hash table in c/c++ ?
posted Dec 26, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The functionality of Hash table can be used by providing c++ map STL,
Program is given below for hash table using map STL

#include<iostream>
#include<map>
#include<string>
#include<utility>
using namespace std;
int main()
{
  string name="neha";
  int empid;

//In map STL string data type is being used as key value and int value their corresponding string value
  map <string,int> employee;
  employee["neha"]=1;
  employee["rajan"]=2;
  employee["ranan"]=3;
  employee["lav"]=4;
  employee["kush"]=5;

  for(map<string,int> ::iterator i=employee.begin();i!=employee.end();i++)
  {
    cout<<(*i).first<<"\t\t"<<(*i).second<<endl;
  }

  map<string,int>:: iterator ii=employee.find(name);
  cout<<ii->second;
  return 0;
}
answer Dec 26, 2015 by Rajan Paswan
Similar Questions
+1 vote

I need a fully functional hash table with time complexity for search O(n). Can someone please help me?

+1 vote

JVM provides garbage collector. Can we do in C ? And what are the efficient ways to implement it in C lang ?

...