我希望地址簿项目的数量是可变的——事先不知道;我在想使用链表是正确的选择吗?
"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/