首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在C++中使用动态内存分配创建数据库

在C++中使用动态内存分配创建数据库
EN

Stack Overflow用户
提问于 2011-01-05 15:21:10
回答 2查看 982关注 0票数 0

我是编程新手,对链表了解不多…帮我编写一个程序--

从用户获取数据并创建您的数据库。

代码语言:javascript
复制
          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;};告诉我现在如何继续...

EN

回答 2

Stack Overflow用户

发布于 2011-01-05 16:08:30

代码语言:javascript
复制
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;

基本的想法是,每当你创建一个新的单元格,你使用‘下一步’指针,以便在链表中链接它。例如,您可以在列表末尾添加一个新单元格:

代码语言:javascript
复制
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;                            
}

代码语言:javascript
复制
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;
}
票数 0
EN

Stack Overflow用户

发布于 2011-01-05 17:08:18

我不会给你的代码,但这些链接肯定会帮助你。

http://en.wikipedia.org/wiki/Linked_list

http://richardbowles.tripod.com/cpp/linklist/linklist.htm

此外,更好的做法是回去参考这本书(正如David在评论中所指出的那样)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4601691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档