[英] tree

查看:52
本文介绍了树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

kandr2的pgs 140-1讨论了递归问题。我尝试输入代码

char by char并且找不到错误所以我只是读了代码并且新的

概念让我跳了出来。也许这就是递归的意思。


struct tnode * addtree(struct tnode *,char *);


在p上声明140.但我在第141页注意到了这一点。


struct tnode * addtree(struct tnode * p,char * w);


可以有人向我解释为什么参数在这里发生变化?他们是否需要在第140-1页上用程序更改



比尔

解决方案

" Bill Cunningham" < no **** @ nspam.invalidwrites:


pgs 140-1 of kandr2谈论递归。我尝试输入代码

char by char并且找不到错误所以我只是读了代码并且新的

概念让我跳了出来。也许这就是递归的意思。



递归和你问的问题之间没有联系。我知道如果你认为你已经看到了一个

的连接,那么这对你来说是无益的答案,但是前面的唯一方法是你解释

你看到的是什么连接。


struct tnode * addtree(struct tnode *,char *);

$ b $ 140在p 140上声明。但我在第141页注意到这一点。


struct tnode * addtree(struct tnode * p,char * w);

有人可以向我解释为什么这里的参数会发生变化吗?



这些差异无任何影响。在函数

声明(注释声明,而不是在函数定义中)中,你可以免费省略参数名称[1]。如果你给它们命名,

名称除了作为(人类)读者的信息之外没有任何力量。


如果你不止一次地重复声明,你可以使用不同的或

随意省略其中的部分或全部,完全没有效果。当你来定义函数时你必须使用
你必须使用名字,但它们不必匹配

你之前在任何声明中所使用过的/>
函数。


他们是否需要使用第140-1页的程序更改



我无法理解这个问题。如果您不包含带有

问题的代码,那么您可以将自己限制在那些拥有您正在讨论的书的确切版本的人的答案中。


[1]有一种特殊情况,其中一个参数是

的维度,另一个是VLA,但我们暂时将其放在一边。 />

-

Ben。




" Bill Cunningham" < no **** @ nspam.invalidwrote in message

news:49 ********************** @ news.suddenlink 。净。 ..


pds 140-1 kandr2谈论递归。我尝试输入代码

char by char并且找不到错误所以我只是读了代码并且新的

概念让我跳了出来。也许这就是递归的意思。


struct tnode * addtree(struct tnode *,char *);


在p上声明140.但我在第141页注意到了这一点。


struct tnode * addtree(struct tnode * p,char * w);



那应该是{最后不是;。这使得它的定义相当于前瞻性声明。


-

Bartc


" Bill Cunningham" < no **** @ nspam.invalidwrites:


pds 140-1 kandr2谈论递归。我尝试输入代码

char by char并且找不到错误所以我只是读了代码并且新的

概念让我跳了出来。也许这就是递归的意思。


struct tnode * addtree(struct tnode *,char *);


在p上声明140.但我在第141页注意到了这一点。


struct tnode * addtree(struct tnode * p,char * w);


可以有人向我解释为什么参数在这里发生变化?他们是否需要使用第140-1页的程序更改



在函数声明中,'不是函数定义的一部分,

参数名是可选的。对于每个参数,您可以指定

或者只是类型(如第一个示例中所示),或者类型和

名称(如第二个示例中所示)。另一方面,在函数*定义*中,你必须指定

名称,因为这就是函数体的知道方式如何参考

参数。


一个简单的例子:


int add_one(int); / *这是一份法律声明* /


int add_one(int i); / *这也是一个法律声明* /


int add_one(int i)/ *这是一个定义;名称i需要* /

{

返回i + 1;

}


我的建议你总是要在函数

声明中包含参数名称,即使它们不是必需的。如果名字总是在那里,事情往往会更加混乱。


这与递归完全无关,我很茫然

明白为什么你会认为它确实如此。我想你看到了这个词

" recursion"在一个页面上,看到附近的这两个声明,并没有理解声明,并且疯狂地猜测他们必须有一些与递归有关的事情。你的这些疯狂的猜测是让学习变得困难得多。我已经好几次向你提到过这个问题。它显然没有做任何好事。


递归意味着一个函数调用自己。我肯定K& R2

比我更好地解释它。


-

Keith Thompson(The_Other_Keith ) ks***@mib.org < http://www.ghoti.net/~kst>

诺基亚

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长


pgs 140-1 of kandr2 talk about recursion. I tried typing in the code
char by char and couldn''t find the bugs so I just read the code and a new
concept to me jumped out. Maybe this is what it means by recursion.

struct tnode *addtree (struct tnode *, char *);

is declared on p 140. But I noticed this on p 141.

struct tnode *addtree (struct tnode *p, char *w);

Can someone explain to me why the parameters are changing here? Would they
need to change more with the program on pages 140-1 ?

Bill

解决方案

"Bill Cunningham" <no****@nspam.invalidwrites:

pgs 140-1 of kandr2 talk about recursion. I tried typing in the code
char by char and couldn''t find the bugs so I just read the code and a new
concept to me jumped out. Maybe this is what it means by recursion.

There is no connection between recursion and the question you ask. I
know that this is unhelpful as an answer if you think you have seen a
connection, but then the only way forward would be for you to explain
what you see as the connection.

struct tnode *addtree (struct tnode *, char *);

is declared on p 140. But I noticed this on p 141.

struct tnode *addtree (struct tnode *p, char *w);

Can someone explain to me why the parameters are changing here?

These differences have no effect whatsoever. In a function
declaration (note declaration, not in a function definition) you are
free to omit the names of the parameters[1]. If you name them, the
names carry no force other than as information to the (human) reader.

If you repeat the declaration more than once, you can use different or
omit some or all of them at will for no effect at all. When you come
to define the function you must use names but they don''t have to match
any that you might have used before in any declarations of the
function.

Would they
need to change more with the program on pages 140-1 ?

I can''t understand this question. If you don''t include code with a
question you limit yourself to answers from people who have the exact
edition of the book you are talking about.

[1] There is special case where one parameter is the dimension of
another that is a VLA, but lets put that to one side for the moment.

--
Ben.



"Bill Cunningham" <no****@nspam.invalidwrote in message
news:49**********************@news.suddenlink.net. ..

pgs 140-1 of kandr2 talk about recursion. I tried typing in the code
char by char and couldn''t find the bugs so I just read the code and a new
concept to me jumped out. Maybe this is what it means by recursion.

struct tnode *addtree (struct tnode *, char *);

is declared on p 140. But I noticed this on p 141.

struct tnode *addtree (struct tnode *p, char *w);

That should be "{" at the end not ";". That makes it a definition rather
than a forward declaration.

--
Bartc


"Bill Cunningham" <no****@nspam.invalidwrites:

pgs 140-1 of kandr2 talk about recursion. I tried typing in the code
char by char and couldn''t find the bugs so I just read the code and a new
concept to me jumped out. Maybe this is what it means by recursion.

struct tnode *addtree (struct tnode *, char *);

is declared on p 140. But I noticed this on p 141.

struct tnode *addtree (struct tnode *p, char *w);

Can someone explain to me why the parameters are changing here? Would they
need to change more with the program on pages 140-1 ?

In a function declaration that''s not part of a function definition,
parameter names are optional. For each parameter, you can specify
either just the type (as in the first example), or the type and the
name (as in the second example).

In a function *definition*, on the other hand, you have to specify the
name, because that''s how the body of the function knows how to refer
to the parameters.

A simple example:

int add_one(int); /* this is a legal declaration */

int add_one(int i); /* this is also a legal declaration */

int add_one(int i) /* this is a definition; the name "i" is needed */
{
return i + 1;
}

My advice to you is always to include the parameter names in function
declarations, even though they''re not required. Things tend to be
less confusing if the names are always there.

This has absolutely nothing to do with recursion, and I''m at a loss to
understand why you would think that it does. I think you saw the word
"recursion" on a page, saw these two declarations nearby, didn''t
understand the declarations, and took a wild guess that they must have
something to do with recursion. These wild guesses of yours are
making learning far more difficult than it needs to be. I have
mentioned this to you several times in the past; it obviously hasn''t
done any good.

Recursion means a function calling itself. I''m sure that K&R2
explains it better than I could.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


这篇关于树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆