本文介绍了链表的结构,通过paramters - Ç的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

?你好,
我已经实现链接的结构,以及与此做了一个列表。

?Hello,I have implemented a struct of link, and with this made a list.

typedef struct link1 {
  char* a;
  char* b;
  int i;
  struct link1* next;
};

和我有功能追加,删除等,从列表中。这些功能获得该列表中的第一链路。问题是使用该信息没有更新的功能之后。
有没有一种方法来传递的第一个环节的参数,这样,名单将更新?
第一个环节是从类型:

and I have functions for append, delete etc, from the list. Those functions get the first link in the list. The problem is the after using the functions the information didn't update.Is there a way to pass the parameter of the first link, such that the list will be updated?The first link is from type:

link1* first;

**我试图返回的第一个环节,它的工作原理,但我已经嵌套函数,我不能回到在外部函数这些链接,所以我认为唯一的办法是通过其他的方式放慢参数

**I have tried to return the first link and it works, but I have nested function and I can't return those links in the external functions, so I think that the only way is to pass the paramter in other way.

现在我送参数是这样的:

Right now I send the parameter like this:

link1* first;
func(first);
void func(link1* l){...}

感谢您!

推荐答案

链接列表操作,比如追加,删除等,必须经常影响到列表中的头节点。例如,当头节点被删除,那么流浆>下一个必须现在假设作为新的表头节点的作用。在这样的情况下,你的指针

Link list manipulations, such as append, delete, etc., must often affect the "head" node in the list. For example, when the "head" node is deleted, then "head->next" must now assume the role as the new list head node. In such a case, your pointer

link1* first;

(指向列表的头节点)必须修改为指向流浆>下一个节点。不幸的是,首先传递给一个函数在这个庄园

(which points to the head node of the list) must be modified to point to the "head->next" node. Unfortunately, passing first to a function in this manor

func(first);

不允许FUNC()来操作,其中第一是指向。为了FUNC()来操作,其中第一指向,您必须通过的第一个地址,以FUNC():

does not allow func() to manipulate where 'first' is pointing. In order for func() to manipulate where 'first' is pointing, you must pass the "address" of first to func():

func(&first);

现在,如果FUNC()执行的操作,如删除节点或添加节点,它将有'第一'的地址,因此它可以改变'第一'指向:

Now, if func() performs an operation such as 'delete node' or 'add node', it would have the address of 'first', and thereby it can change where 'first' is pointing:

func(struct link1 **first);
   {
   ...
   *first = head->next;
   ...
   }

这篇关于链表的结构,通过paramters - Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 18:26