【发布时间】:2015-09-24 05:44:51
【问题描述】:
我是指针的新手,并且有此代码用于合并排序的链表。在这里它声明了一个虚拟节点为struct node dummy;,并且虚拟节点的下一个节点为NULL,所以我们使用dummy.next = NULL;来设置它。
/* 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* 有什么区别??
【问题讨论】:
-
Dummy 不是指针,所以
->不起作用。->仅用于指针。 -
所以基本上你问指针和普通变量之间的区别?