473,804 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tree

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
Nov 15 '08 #1
13 1556
"Bill Cunningham" <no****@nspam.i nvalidwrites:
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.
Nov 15 '08 #2

"Bill Cunningham" <no****@nspam.i nvalidwrote 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

Nov 15 '08 #3
"Bill Cunningham" <no****@nspam.i nvalidwrites:
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_Keit h) 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"
Nov 15 '08 #4

"Ben Bacarisse" <be********@bsb .me.ukwrote in message
news:87******** ****@bsb.me.uk. ..
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.
A declaration of say int func (int *, int *);
later change in the program to
int func (int *i, int *i);
later on, and then to something else later or would the body of the function
need to change?

Bill

Nov 15 '08 #5

"Keith Thompson" <ks***@mib.orgw rote in message
news:ln******** ****@nuthaus.mi b.org...
Recursion means a function calling itself. I'm sure that K&R2
explains it better than I could.
I'm not quite sure of what it is yet. With a struct is it like this ?

struct node {
int i;
char c;
struct node one;
struct node two;
};

I am so glad there is a C community to go to with these questions and
kandr2. It seems like right now I'm learning more but it's so fuzzy that it
might *settle wrong* or in other words I might learn it wrong.

I think I can take the trees on p 140-1 and § 6.5 and write a tree
program. I tried coping word from word and got too many bugs.

Bill
Nov 15 '08 #6
On Fri, 14 Nov 2008 19:36:27 -0500, "Bill Cunningham"
<no****@nspam.i nvalidwrote:
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.
The recursion talked about on page 140 is a "recursive declaration"
which they further describe as struct tnode containing a pointer to an
instance of a struct tnode. They then go on to call this a
"self-referential structure" which is a better term since the struct
does not actually contain itself but only a pointer (reference) to
itself.

The recursion talked about on page 141 is the function addtree calling
itself. This is what is usually meant when talking about 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);
NO, you did not notice this on page 141. The line of code in question
on page 141 is the start of the function definition and does not
contain any semicolons.
>
Can someone explain to me why the parameters are changing here? Would they
need to change more with the program on pages 140-1 ?
The parameters didn't change at all. The first is a pointer to struct
and second is a pointer to char. The difference in the code is that
for the function definition the parameters must have names while in
the prototype they are optional and usually omitted.

--
Remove del for email
Nov 15 '08 #7
Bill Cunningham wrote:
"Keith Thompson" <ks***@mib.orgw rote in message
news:ln******** ****@nuthaus.mi b.org...
>Recursion means a function calling itself. I'm sure that K&R2
explains it better than I could.

I'm not quite sure of what it is yet. With a struct is it like
this ?
struct node {
int i;
char c;
struct node one;
struct node two;
};
No, that's nor a function calling itself, it is a struct containing itself
and as such illegal/impossible.

What you can do is:

struct node {
int i;
char c;
struct node *one;
struct node *two;
};

i.e. have pointers to the struct inside the struct.
But still this hasn't got anything to do woth recursive functions.

Bye, Jojo
Nov 15 '08 #8
"Bill Cunningham" <no****@nspam.i nvalidwrites:
"Ben Bacarisse" <be********@bsb .me.ukwrote in message
news:87******** ****@bsb.me.uk. ..
>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.
These bits you quote don't seem to have anything to with the question
you go one to ask.
A declaration of say int func (int *, int *);
later change in the program to
int func (int *i, int *i);
later on, and then to something else later or would the body of the function
need to change?
I think the answer is no but the question is a bit fuzzy. The names
used in the declaration of a function have no effect on the body of
the function.

--
Ben.
Nov 15 '08 #9

"Joachim Schmitz" <no*********@sc hmitz-digital.dewrote in message
news:gf******** *@online.de...
What you can do is:

struct node {
int i;
char c;
struct node *one;
struct node *two;
};

i.e. have pointers to the struct inside the struct.
But still this hasn't got anything to do woth recursive functions.
So basically what your saying is that recursion in C involves pointer ?
Right?

Bill
Nov 16 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7960
by: Jeffrey Silverman | last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree structure from that list. Basically, I want to turn this: $list = array( array( 'id' => 'A', 'parent_id' => null, 'value' => 'aaa') , array( 'id' => 'B', 'parent_id' => 'A', 'value' => 'bbb') , array( 'id' => 'C', 'parent_id' => 'B', 'value' => 'ccc') , array( 'id' => 'D', 'parent_id' => 'A', 'value' => 'ddd')
0
2184
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i am able to check using xpath in asp.net 2.0 till MenuItem node. if i check visible attribute value till SubMenuLevel0 node then in tree it will not display the MenuItem Node at all Note: My tree Menu will start from MenuItem node and it will...
4
9023
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working, even the removal, I just don't know how to keep track of the parent, so that I can set its child to the child of the node to be removed. IE - if I had C / \ B D
2
1638
by: New | last post by:
Why does this code insert a node into a binary search tree correctly? If I only inserting going by first digit it works properly but when I try inserting going by the whole ip and the port number the inserts are totally out of order. where IPAddress is four ints Node is an IPAddress, portNumber, left pointer and right pointer Nodeptr is a pointer to a Node
5
1993
by: Mike | last post by:
Why does this code insert a node into a binary search tree correctly? If I only inserting going by first digit it works properly but when I try inserting going by the whole ip and the port number the inserts are totally out of order. where IPAddress is four ints Node is an IPAddress, portNumber, left pointer and right pointer Nodeptr is a pointer to a Node
2
3489
by: Kiran | last post by:
Hello all, I am using a tree to display stuff, and it is constantly updated, but what I have noticed is in the lowest level, there is clearly noticable cutoff of the text I place there. The cutoff is existent even if I do not update the text inside the tree constantly. It seems that the text is halfway below where it should line up. I tried placing an image to see if that would correct it, but it does not. The image is perfectly lined up,...
1
4835
by: Satish.Talyan | last post by:
hi, i want to create a dynamic tree hierarchy in javascript.there are two parts in tree, group & user.when we click on group then users come under that's tree category will be opened.problem is that i am not able to arrange three things simultaneously,group,users & there functionality simultaneously.dynamic means group & users come from database and groups & users can be increased in number at any time. i am sending code for that tree...
1
2954
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template <typename Tclass Tree{ private: Tree<T*left;
4
11016
by: whitehatmiracle | last post by:
Hello I have written a program for a binary tree. On compiling one has to first chose option 1 and then delete or search. Im having some trouble with the balancing function. It seems to be going into an infinite loop, i think im messing up with the pointers. Heres the code. //press 1, first, Do not press it a second time!!!
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.