📄 16.c
字号:
#include "stdio.h"
#include "malloc.h"
#include "string.h"
typedef struct node{
char pos[3];
struct node *next;
}Hnode;
int times=0;
void creathash(Hnode data[],char key[]){
int value;
Hnode *temp,*p;
temp=(Hnode *)malloc(sizeof(Hnode));
strcpy(temp->pos,key);
temp->next=NULL;
value=key[0]-65;
value=value/2;
if (data[value].next==NULL) data[value].next=temp;
else {
p=data[value].next;
while(p->next!=NULL)p=p->next;
p->next=temp;
p=p->next;
}
}
void search(Hnode data[],char key[]){
int value;
Hnode *p;
value=(key[0]-65)/2;
p=data[value].next;
while(p!=NULL)
{
if(strcmp(p->pos,key)==0)
{
times++;
printf("\nThe compare times is :%d",times);
return;
}
else {times++;p=p->next;}
}
if(p==NULL)printf("Not found!");
}
void main(){
Hnode hash[13];
int i;
char key[2];
for(i=0;i<14;i++)
{
hash[i].pos[0]=(char) (i);
hash[i].next=NULL;
}
for(i=0;i<12;i++)
{
printf("Input key %d:",i);
gets(key);
creathash(hash,key);
}
printf("Input the wantted key(Jan etc.):");
gets(key);
search(hash ,key);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -