7050 The outer zipper method solves hash conflicts and builds a hash table

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
    
    
int data;
struct node *next;
}no;
int main()
{
    
    
    no n[100];
    int key,h;
    for(int i=0;i<13;i++)
    n[i].next=NULL;

cin>>key;
while(key){
    
    
h=key%13;

no* q=new no;
q->data=key;
q->next=n[h].next;
n[h].next=q;

cin>>key;
}

for(int i=0;i<13;i++){
    
    
cout<<i<<':';
no *p=n[i].next;
while(p!=NULL){
    
    
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}


    return 0;
}

Guess you like

Origin blog.csdn.net/changbaishannefu/article/details/111225084