c - 在 C 程序中为地址簿设计数据结构?

标签 c

我希望地址簿项目的数量是可变的——事先不知道;我在想使用链表是正确的选择吗?

"The user can enter new person data, or print the data for a given name, the asking data need not be a name but also an address on a telephone number, the program prints the whole information about a person, print the content of the book in alphabetical order. Store some data in a file; retrieve it and safe it after modification.

Program should write a file to the disk and retrieve the file from it. Program should be called with arguments."

我将使用 malloc,但我不知道何时以及如何使用。

请问有没有人做过类似的任务或有可以帮助我的想法?

最佳答案

对于一个“玩具”程序,一个链表就足够了。链表的问题是如果你有很多记录。在最坏的情况下,您将不得不搜索整个列表以查找或不查找条目。最好的方法是散列或散列和树的组合。如果您使用指针,则必须使用 malloc() 来确定。我建议您检查 Wikipedia article关于链表实现。他们甚至有一个 C 语言的例子。

关于c - 在 C 程序中为地址簿设计数据结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2708544/

相关文章:

从内核代码调用系统调用

c++ - int 与 unsigned char

c - 如何从 10 个字符串的数组中打印 5 个唯一的字符串

c - 使用 Xlib 函数在 GtkDrawingArea 上绘图

C 使用伯克利套接字发送文件

c - 打印两次 NASM

c - 我正在为纸牌游戏编写代码。在我的交易卡功能中,程序卡住了,我无法确定原因

c - 在 OpenMP 的 C 语言中使函数线程安全

c - 编译C程序时出错

python - 类似于Python的 "if x in list"的C命令