问题描述
- 哈希表电话本问题求大神解决
-
各位大神,我不知道要怎么把这些代码给组合起来void InHash(pointer p[]) { pointer t=new HsNode(); cout<<"输入用户姓名:"; cin>>t->Name; cout<<"输入用户号码:"; cin>>t->PhoneNumber; cout<<"输入用户地址:"; cin>>t->Address; t->next=NULL; int a=Sum(t->PhoneNumber); int b=a%7; if(p[b]==NULL) { p[b]=t; } else { pointer r; r=p[b]; while(r->next!=NULL) { r=r->next; } r->next=t; } } void OutHash(pointer p[],char ch[]) { int a=Sum(ch); int b=a%7; pointer r=p[b]; if(!strcmp(r->PhoneNumber,ch)) { p[b]=r->next; delete r; return; } pointer s=r; while(1) { r=r->next; if(!strcmp(r->PhoneNumber,ch)) { s->next=r->next; delete r; return; } else { s=r; } } } void SearchHash(pointer p[],char ch[]) { int a=Sum(ch); int b=a%7; pointer r=p[b]; if(r==NULL) { cout<<"没有该号码。"<<endl; return; } if(!strcmp(r->PhoneNumber,ch)) { cout<<"其他信息为:"<<endl; cout<<"姓名为:"<<r->Name<<endl; cout<<"地址为:"<<r->Address<<endl; return; } if(r!=NULL&&r->next==NULL) { cout<<"没有该号码。"<<endl; return; } pointer s=r; while(1) { r=r->next; if(!strcmp(r->PhoneNumber,ch)) { cout<<"其他信息为:"<<endl; cout<<"姓名为:"<<r->Name<<endl; cout<<"地址为:"<<r->Address<<endl; return; } else if(r->next==NULL) { cout<<"没有该号码。"<<endl; return; } else { s=r; } } }
时间: 2024-09-24 23:24:25