#include <iostream> #include <string.h> #define MAX using namespace std;
Template<typename type> struct Node {Type *data;
Node *next;
Node (const Type *STR = ""):d ATA (new Type[strlen (str) + 1]), next (NULL) {strcpy (DATA,STR);
}
};
Template<typename type> struct Mnode {node<type> *adj;
int count;//count.
Mnode (): Adj (NULL), COUNT (0) {}}; Template<typename type> class Hash {Public:hash () {} long Hash (const char *str) {const char *p
= str;
Long nhash=0;
while (*p) Nhash = (Nhash << 5) + Nhash + *p++;
return nhash;
TIMES33 algorithm.
} void Insert (const char *str) {node<type> *s = new node<type> (str);
Long key = hash (str)%max;
node<type> *p = Node[key].adj;
node<type> *PR = NULL;
while (P!= NULL) {PR = p;
p = p->next;
} if (pr = NULL) {Node[key].adj = s;
else {s->next = p;
Pr->next = s;
} node[key].count++;
void Printf () {int i = 0;
node<type> *p = NULL;
for (; i < MAX; i++) {if (node[i].count>0) {p = Node[i].adj;
while (P!= NULL) {cout << p->data << "";
p = p->next;
} cout << Endl;
}}} private:mnode<type> Node[max];
};
int main () {hash<char> sh; Sh.
Insert ("Liuuiyan"); Sh.
Insert ("Benleng"); Sh.
Insert ("Huang"); Sh.
Printf ();
return 0; }