#include <stdio.h>
#include <windows.h>
int HelpPosition;
int position;
typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node
{
ElementType data;
int ListPosition;
struct Node *next;
};
typedef PtrToNode List;
typedef struct TblNode *HashTable;
struct TblNode {
static int TableSize;
List Heads;
};
int TblNode::TableSize = 11;
HashTable CreateTable()
{
HashTable H;
int i;
H = (HashTable)malloc(sizeof(struct TblNode));
H->Heads = (List)malloc(H->TableSize*sizeof(struct Node));
for( i=0; i<H->TableSize;i++)
{
H->Heads[i].next = NULL;
}
return H;
}
List Find(HashTable H,ElementType Key)
{
List P;
HelpPosition = 1;
position = Key % H->TableSize;
P = H->Heads[position].next;
while( P!=NULL && P->data != Key)
{
P = P->next;
HelpPosition++;
}
return P;
}
bool Insert(HashTable H,ElementType Key)
{
List P,NewP;
P = Find(H,Key);
if(!P)
{
NewP = (List)malloc(sizeof(struct Node));
NewP->data = Key;
NewP->ListPosition = HelpPosition;
position = Key % H->TableSize;
NewP->next = H->Heads[position].next;
H->Heads[position].next = NewP;
return true;
}
}