【发布时间】:2020-11-29 17:39:11
【问题描述】:
我开始使用 Ubuntu 来适应 Linux 环境,但我的代码遇到了这个奇怪的问题,它给了我以下错误:
HashTable_SeparateChaining.c:60:1: error: expected identifier or ‘(’ before ‘{’ token
60 | {
| ^
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
struct list_node
{
struct list_node *next;
char *key;
char *value;
};
struct hash_table
{
int table_size;
struct list_node **list_arr;
};
unsigned int hash(const char *key, unsigned int table_size);
struct hash_table *initialize(unsigned int table_size);
struct list_node *find(struct hash_table *H, const char *key);
void insert(struct hash_table *H, const char *key, const char *value);
void dump(struct hash_table *H);
unsigned int
hash(const char *key, unsigned int table_size)
{
unsigned long int hash = 0;
for(int i=0;key[i];i++)
{
hash = (hash<<5) + key[i];
}
return (hash%table_size);
}
struct hash_table
*initialize(unsigned int table_size)
{
struct hash_table *H = malloc(sizeof(*H));
H->list_arr = malloc(sizeof(*H->list_arr)*table_size);
/*H->table_size = table_size;*/
for(unsigned int i = 0; i<table_size; i++)
{
H->list_arr[i] = malloc(sizeof(*H->list_arr[i]));
H->list_arr[i]->next = NULL;
}
}
struct list_node
*find(struct hash_table *H, const char *key);
{
unsigned int hash = hash(key,H->tablesize) ;
struct list_node *current = H->list_arr[hash];
/* more code... */
}
int main()
{
return 1;
}
我不知道问题可能是什么。我正在哈希表上练习我的分离链接方法,它还没有完成。请帮我解决这个问题,谢谢。
【问题讨论】:
-
请不要用作为答案给出的代码更新您的问题。这样做会使答案完全无效。
标签: c linux data-structures compiler-errors