Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
HashTabFold
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////// //HashTabFold:Understanding Hash Table where folding method is used for hashing //class HashT code credit goes to www.programiz.com & www.educba.com,HashFold() code credit goes to www.indiastudychannel.com. For more see https://www.indiastudychannel.com/experts/3245-hashing-by-folding-using-c //Template modifications and main driver code are created by Rezaul Hoque on September 17,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; /////////////////////////////////////////////////////////////////////////// #include <iostream> #include <string> #include <list> #include <cmath> template <class T> class HashT{ int sz; std::list<T> *tab; public: HashT(int n){ this->sz=n; tab=new std::list<T>[sz];} int HashFold(int x) { int z,y=2,s=0,s1=0,e; int flag=0,h,index; z=pow(10,y); while(x>0) { e=x%z; x=x/z; if(flag==0) { while(e>0) { h=e%10; e=e/10; s1=s1*10+h; } flag=1; e=s1; } s=s+e; } index=s%sz; return index; } void insert (int key, T data){ tab[HashFold(key)].push_back(data); } void print(){ int i; for(i=0;i<sz;i++){ std::cout<<i<<" "<<"\n"; for(auto p : tab[i]) std::cout<<"->"<<p<<"\n"; } } }; int main() { std::string s[]={"Hi","Hola","Ni Hao","Salut","Konnichiwa","Salam","Namastey"}; int k[]={112,321,322,234,333,111,200}; int size =sizeof(k)/sizeof(k[0]); HashT<std::string> h(size); for(int r=0;r<size;r++) h.insert(k[r],s[r]); h.print(); return 0; }
run
|
edit
|
history
|
help
0
QuadRootPoint
Korelacja Pearsona lol
Complete Over-Use of Functor Templates (Academic Experiment)
max_recursion
palindrome
abhilash
Income calculator
Best time to buy and sell stocks
Translating binary to decimal numbers
offsetof