简体   繁体   English

在结构中声明双链表

[英]Declaration of a doubly linked list in a structure

Is this the correct procedure in declaring a doubly linked list within a structure.I'm using the structure to read in a text file if this has any relevance. 这是在结构中声明双链表的正确过程吗?如果有任何相关性,我正在使用该结构读取文本文件。

#define MAX 20
//struct to order contactList
struct contact
{
    string firstName[MAX],lastName[MAX],email[MAX],companyName[MAX];
    long phoneNum[MAX];
    struct listelement *link
    struct node *next;
    struct node *prev;

};

Probably not. 可能不是。 Normally, you'd use struct contact *next; struct contact *prev; 通常,您将使用struct contact *next; struct contact *prev; struct contact *next; struct contact *prev; since the items in the list are (probably) struct contact and not struct node . 因为列表中的项目是(可能)是struct contact而不是struct node

Hence, I'd expect to see: 因此,我希望看到:

#define MAX 20
//struct to order contactList
struct contact
{
    string              firstName[MAX];
    string              lastName[MAX];
    string              email[MAX];
    string              companyName[MAX];
    long                phoneNum[MAX];    /* 20 phone numbers per contact — wow! */
    struct listelement *link;             /* Semi-colon added.  What is this for? */
    struct contact     *next;
    struct contact     *prev;
};

The email element of the structure is too short (my main email address wouldn't fit, for example; you need 32 bytes at least, I suggest). 该结构的email元素太短(例如,我的主要电子邮件地址不适合;我建议您至少需要32个字节)。 That's an awful lot of phone numbers for a single contact. 单个联系人的电话号码太多了。 Also, long will not store all 10-digit phone numbers. 另外, long不会存储所有10位电话号码。

It is not clear what the link element is for. link元素是做什么的还不清楚。 It presumably is part of a singly-linked list involving these structures. 它可能是包含这些结构的单链接列表的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM