我正在开发一个C程序,它需要我创建一个列表和一些函数(我已经完成),然后实现这样的哈希表。该程序作为输入字,已经通过其积极性(0-4),0为负等等进行评级。
typedef struct {
int size;
int num_entries;
entryT *table;
} hashT;
哈希表必须至少具有以下功能:
以下是我实施的列表的功能。
struct Node {
struct Node *next;
char* word;
int count;
int score;
} *head;
int AddtoList(char *lexi,int skor) {
struct Node *add = (struct Node*)malloc (sizeof(struct Node*));
if (add == NULL) {
exit(1);
}
add = head;
int found = 1;;
while (strcmp(add->word, lexi) != 0) {
add = add->next;
found=0;
}
if (found == 1) { //uparxei hdh sti lista
add->count++;
add->score;
return 1;
}
else {
struct Node *temp = (struct Node*)malloc (sizeof(struct Node*));
if (temp == NULL) exit(23);
strcpy(temp->word,lexi);
temp->score = skor;
temp->count++;
if (head == NULL) { //adeia lista
*head = *temp;
head->next = NULL;
}
else {
temp->next = head;
*head = *temp;
}
return 1;
}
}
void Print() {
struct Node *temp;
temp = head;
if (temp == NULL) {
printf("Empty List-> Exiting\n");
}
while (temp != NULL) {
if (temp->next != NULL) {//an o epomenos komvos den einai teleftaios
printf("[ ");
printf("%c %d 0.2%d", temp->word, temp->count, temp->score);
printf("]");
printf(", ");
}
else {
printf("[ ");
printf("%c %d 0.2%d", temp->word, temp->count, temp->score);
printf("]");
printf("\n");
}
temp = temp->next;
}
}
void DeleteList(struct Node *head) {
struct Node *current = head;
struct Node *next;
while (current != NULL) {
next = current->next;
free(current);
current = next;
}
head = NULL;
}
char* FindNode(char *lexi) {
struct Node *current = head;
struct Node *next;
while(strcmp(current->word, lexi) != 0) {
next = current->next;
}
return (current->word);
}
struct hashT{
int size;
int num_entries;
struct Node table;
} *hash;
我想要的是我可以通过哈希表函数获得的任何帮助。如果您需要我发布有关该计划的任何其他信息,请告诉我。
谢谢!