Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
LP
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////////LP:understanding Linear Probing in hashing //this code is created by Rezaul Hoque on September 09,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> class LP{ int n=7; int k[7]; int v[7]; public: LP(int s[],int t[]){ for(int i=0;i<n;i++){ k[i]=s[i]; v[i]=t[i]; } } 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=k[i]%n; if(tab[h]== -1) { tab[h]=k[i]; val[h]=v[i]; } else { for(int j=0;j<n;j++){ int q=(h+j)%n; if(tab[q]== -1) { tab[q]=k[j]; val[q]=v[j]; break; } } } } for (int i=0;i<n; i++) std::cout<<tab[i]<<" "<<val[i]<<"\n"; } }; int main(){ int a[]={700,103,107,109,111,113,115}; int val[]={90,32,24,51,70,30,11}; LP lh(a,val); lh.hash(); return 0; }
run
|
edit
|
history
|
help
0
anagram
RegexReplace
replace_if-30-Seconds-of-C++
idfc
Boost phoenix. e.g 3 phoenix: functor
stack::swap_30-Seconds-of-C++
Radix
Problem: binary
a ko z and z ko n string printing
IAR compiler bug test code