rendered paste body#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define num_of_lists 16
struct node
{
char* data;
struct node* next;
};
unsigned int hasher(char* word)
{
unsigned int l=strlen(word);
unsigned int n=0;
while(l--) n += word[l];
return n%num_of_lists;
}
int check_hash_table(char* word, struct node** table) // 2nd Argument Pointer?
{
struct node* list_node;
unsigned int hash;
hash = hasher(word);
list_node = table[hash];
while(list_node->next != 0){
list_node = list_node->next;
if(strcmp(list_node->data,word)) continue;
return 0;
}
list_node->next = malloc(sizeof(struct node));
list_node = list_node->next;
list_node->next = 0;
list_node->data = malloc(strlen(word)+1);
strcpy(list_node->data, word);
return 1;
}
int main(int argc, char** argv)
{
unsigned int i;
struct node hash_table[num_of_lists+1];
for(i=0;i<num_of_lists+1;i++){
*(hash_table+i)->data = 0;
*(hash_table+i)->next = 0;
}
for(i=1;i<=argc;i++)
if(check_hash_table(argv[i],(struct node*) hash_table))
printf("%s",argv[i]);
}