#include<stdio.h>
#include<malloc.h>
int m=20;
typedef struct node
{
int data;
struct node *next;
}node;
typedef struct nodelist
{
int count;
node * start;
}nodelist;
int hash(int i)
{
int pos=i%m;
return pos;
}
void insert(nodelist* a,int i)
{
int j=hash(i);
node * bt=(node *)malloc(sizeof(node));
bt->data=i;
bt->next=NULL;
if(a[j].count==0)
{
a[j].start=bt;
a[j].count++;
}
else
{
bt->next=a[j].start;
a[j].start=bt;
a[j].count++;
}
}
void search(nodelist *a,int x)
{
int pos=hash(x);
if(a[pos].count==0)
printf("NOT EXIST!\n");
else
{
int i=a[pos].count;
int j=1;
node *s=a[pos].start;
while(j<=i)
{
if(s->data==x)
{
printf("EXIST!\n");
break;
}
else
{
j++;
s=s->next;
}
}
if(j>i)
printf("NOT EXIST!\n");
}
}
int main()
{
nodelist a[20];
for(int i=0;i<20;i++)
{
a[i].start=NULL;
a[i].count=0;
}
insert(a,2);
// insert(a,3);
// insert(a,22);
search(a,24);
return 0;
}