我是编程新手,对链表了解不多…帮我编写一个程序--
从用户获取数据并创建您的数据库。
a>Data: Name, Age, Date of birth
b>Memory for each entry should be dynamically created.我已经创建了一个结构-结构数据库{ char name25;int age5;int dob10;struct database *next;};告诉我现在如何继续...
发布于 2011-01-05 16:08:30
struct database {
char name[25];
int age[5];
// in my opinion you should only keep dob, since age would have to be constantly updated
int dob[10];
struct database *next;
} TCel, *TList, **Alist;基本的想法是,每当你创建一个新的单元格,你使用‘下一步’指针,以便在链表中链接它。例如,您可以在列表末尾添加一个新单元格:
AList InsEnd(AList aL, Info e)
{
TLista aux;
// allocate cel and set the information inside it
aux = AlocCel(e);
if (!aux) return aL;
while (*aL != NULL)
aL = &(*aL)->next;
// linking the node
*aL = aux;
return aL;
}或
TList InsEnd2(TList aL, Info e)
{
TLista aux;
aux = AlocCel(e);
if(!aux) return aL;
while(aL->next != NULL)
aL = aL->next;
// linking the node
aL->next = aux;
return aL;
}发布于 2011-01-05 17:08:18
我不会给你的代码,但这些链接肯定会帮助你。
http://en.wikipedia.org/wiki/Linked_list
http://richardbowles.tripod.com/cpp/linklist/linklist.htm
此外,更好的做法是回去参考这本书(正如David在评论中所指出的那样)
https://stackoverflow.com/questions/4601691
复制相似问题