结构节点指针分配

问题描述 投票:-1回答:1

我有一个作业,其中包含结构节点,并且在其中一个功能中,其编写顺序为current-> next-> Firstname,我的问题是:current-> next-> Firstname的数据类型是什么?谢谢。代码的相关部分如下:

typedef struct node
{
    char Lastname[50];
    char Firstname[50];
    char Initials[50];
    char Mobile[50];
    char Class[50];
    char InitialSort[50];
    char RandomSort[50];

    struct node *next;
} node;

node *HEAD=NULL;

// more code here.

void sortedInsert(node** head_ref,node* new_node)
{
    node* current;
    // Special case for the head end
    if (*head_ref == NULL || (*head_ref)->Firstname >= new_node->Firstname)
    {
        new_node->next = *head_ref;
        *head_ref = new_node;
    }

    else
    {
        // Locate the node before the point of insertion
        current = *head_ref;
        while (current->next!=NULL && strcmp(current->next->Firstname, new_node->Firstname)<0 )
        {
            current = current->next;
        }
        new_node->next = current->next;
        current->next = new_node;
    }
}
c sorting pointers linked-list structure
1个回答
0
投票
跟随指针理解,该结构只是一大组分配的数据。所以current-> next只是读取列表中下一个节点的地址。从那里要求找到Firstname变量。这将跳到“下一个”节点的Firstname的第一个元素的地址。
© www.soinside.com 2019 - 2024. All rights reserved.