【问题标题】:C: Struct syntax Linked ListsC:结构语法链表
【发布时间】:2014-02-04 18:10:33
【问题描述】:

是以下

typedef struct node {
    int data;
    struct node* next;
} node;

定义struct 的唯一方法是不必在里面写出struct 使用它时程序的其余部分?

即通过上述struct,以下工作正常:

node* head = NULL;

但是,有没有其他方式来表达通常被认为更好的struct

【问题讨论】:

  • 解释一下:更好是什么意思?
  • 不那么冗长,不会对理解产生负面影响。

标签: c struct linked-list singly-linked-list


【解决方案1】:

没有。你也可以这样做:

struct node {
    int data;
    struct node* next;
};
typedef struct node node;

“更好”并不是真正可以应用于这些的限定词;据我所知,两者都没有优势。

【讨论】:

    【解决方案2】:

    不!你很准。在 C++ 中这不是必需的,但在 C 中,有些人(例如 Linux 内核)更喜欢将事物保留为结构 (see here)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 2023-03-11
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    相关资源
    最近更新 更多