Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
HashFold
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////////HashFold:understanding folding method in hashing //fold() code credit goes to www.India study channel.com. For more see https://www.indiastudychannel.com/experts/3245-hashing-by-folding-using-c //the rest is created by Rezaul Hoque on September 16,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 <cmath> class QP{ int n=7; int y=4; int k[7]; int v[7]; public: QP(long int s[],int t[]){ for(int i=0;i<n;i++){ k[i]=s[i]; v[i]=t[i]; } } int fold(long int x) { unsigned long int z,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%n; return index; } void hash(){ int tab[n]; int val[n]; for(int i=0;i<n;i++){ tab[i]= -1; val[i]=-1; } for(int i=0;i<n; i++){ int h=fold(k[i]); if(tab[h]== -1) { tab[h]=k[i]; val[h]=v[i]; } } for (int i=0;i<n; i++) std::cout<<tab[i]<<" "<<val[i]<<"\n"; } }; int main(){ long int a[]={123456789,12345,987654,1113245,1117654,1256770,123456795}; int val[]={90,32,24,12,32,56,89}; QP qh(a,val); qh.hash(); return 0; }
run
|
edit
|
history
|
help
0
c++ car racing game
Metodos
HeapSort
顺序表的实现——静态分配
mytemp
CODE K
PointClassOpLoad
LRU - Main
Continuous Sub Set with given sum
prepend