#include
#include
typedef struct node
{
int data;
struct node *next;
}node;
init_hash(node **A,int n)
{
int i;
for(i=0;idata=0;
A[i]->next=NULL;
}
}
insert_hash(node **A,int value,int n)
{
int key;
node *p,*q;
key=value%n;
if(A[key]->next!=NULL)
{
p=A[key]->next;
while(p->next!=NULL)
p=p->next;
q=(node *)malloc(sizeof(node));
q->data=value;
q->next=NULL;
p->next=q;
}
else
{
q=(node *)malloc(sizeof(node));
q->data=value;
q->next=NULL;
A[key]->next=q;
}
}
int search_hash(node **A,int value,int n)
{
int key;
node *p;
key=value%n;
if(A[key]->next==NULL)
return 0;
else
{
p=A[key]->next;
while(p!=NULL)
{
if(p->data==value)
return 1;
}
return 0;
}
}
delete_hash(node **A,int value,int n)
{
int key;
node *p,*q;
key=value%n;
p=A[key];
q=A[key]->next;
while(q->data!=value)
{
p=q;
q=q->next;
}
p->next=q->next;
free(q);
}
print_hash(node **A,int n)
{
int i;
node *p;
for(i=0;inext!=NULL)
{
p=A[i]->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
}
printf("\n");
}
main()
{
int i,n,value,Case;
node **A;
printf("输入待排序元素个数:\n");
scanf("%d",&n);
A=(node **)malloc(sizeof(node*)*n); //申请一个指针型数组A[n]
init_hash(A,n);//初始化数组A
printf("输入hash表的值(空格键分开):\n");
for(i=0;i
1