#include<iostream> using namespace std; int hashCode(char c){ -if(c>='a'&&c<='z') --return (int)c-'a'+1; -return (int)c-'A'+1; } int hashFunction (string x){ -int r=0; -for(int i=1; i<=x.size() ;i++) --r+= hashCode(x[i-1]) * i; -return r; } struct contact{ -string name,number; -contact *next; } *hash_table[100]; void insert(int index, contact *c){ -if(hash_table[index%100]==NULL){ --hash_table[index%100]= c; --return; -} -contact *p = hash_table[index%100]; -while(p->next != NULL) --p = p->next; -p->next = c; -return; } int main(){ -string ans; -do{ --contact *c= new contact; --cout<<"Name: "; --cin>>c->name; --cout<<"Number: "; --cin>>c->number; --c->next = NULL; --int index = hashFunction(c->name); --insert(index, c); --cout<<"Do you have another contact? "; --cin>>ans; -}while(ans=="yes"); -for(int i=0; i<100; i++) --if(hash_table[i]!=NULL){ ---contact *p = hash_table[i]; ---while(p!=NULL){ ----cout<<p->name<<endl; ----cout<<p->number<<endl; ----p = p->next; ---} --} }