gpt4 book ai didi

c - 在 C 中初始化哈希表?

转载 作者:行者123 更新时间:2023-11-30 20:37:08 26 4
gpt4 key购买 nike

我正在为 C 类做一些作业,但我不知道如何处理这个问题。我被告知“从堆中分配一个带有 htsize 存储桶的哈希表,每个存储桶最初都是空的。”我已经通过命令行参数指定了 htsize ,并在以下代码中将其设置为全局变量:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int htsize;
int main(int argc, char *argv[])
{
if (argc <= 1)
{
printf("Please declare a table size");
return 1;
}
htsize = atoi(argv[1]);
}

但我不确定“从堆分配”意味着什么。有人可以帮我解决这个问题吗?

最佳答案

C 不提供标准数据类型哈希表,您必须实现一个。另外,请避免使用atoi,因为它是一个非常“不安全”的函数,并且通常会避免使用它。

已经实现的实现已广泛使用,例如: https://gist.github.com/tonious/1377667

关于c - 在 C 中初始化哈希表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33556960/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com