我是新来的指针,有这种代码合并排序的链接列表。在这里它已经声明一个虚拟节点为struct node dummy;
,虚拟节点的下一个节点为NULL,所以要设置它我们使用dummy.next = NULL;
。struct node和struct node *之间的' - >'有什么区别?
/* Link list node */
struct node
{
int data;
struct node* next;
};
struct node* SortedMerge(struct node* a, struct node* b)
{
/* a dummy first node to hang the result on */
struct node dummy;
/* tail points to the last result node */
struct node* tail = &dummy;
/* so tail->next is the place to add new nodes
to the result. */
dummy.next = NULL;
//Code continues...
}
我知道我可以使用它,如果它是struct node *dummy;
,但因为它不是一个指针节点,我们不能在这里使用它。 所以我的问题是为什么dummy->next = NULL
在这里工作? 和struct node和struct node *之间的区别是什么?
虚拟不是一个指针,所以' - >'不起作用。 ' - >'仅用于指针。 – juanchopanza
所以基本上你会问指针和普通变量之间的区别吗? – ameyCU