473,549 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recursive function, where am I?

Hi all,

using C#, .NET 1.1, ASP.NET

I have created a recursive??? function. It looks a little like...

MyContext.Curre nt.Folder.Paren t.Parent.Parent .Parent.Name

As you can see, Parent is the recursive??? part.

Say I start from
/root/Folder1/Folder2/Folder3/Folder4/Folder5, I need to somehow record
where I am in the list, so that when I get to .Name, I see "Folder1".

Is there an easy way to see how many steps I have taken with Parent to reach
the folder name?

I had thought of using a property, but if I then call another similar
routine later, the property will remain.

I am thinking out loud here... this maybe a solution. Please glance your
eyes over it and let me know if it will work and if there are likely to be
any problems. What I do not know is if I reach the ".Folder", whether the
..Folder routine actually gets called before I run the .Parent, if you see
what I mean.

1. Set up a CurrentFolder property.
2. in .Folder, reset the CurrentFolder property to the actual folder where
we are at, i.e. "/root/Folder1/Folder2/Folder3/Folder4/Folder5"
3. Each time .Parent is called, change the CurrentFolder property to the new
Folder Path.
4. When Name is called, read off the CurrentFolder.

Will this actually run?

I may have a scope problem here as well...
MyContext is a class that has a "Folder" property, which is based on a
Folders class. The Folders class has "Parent", which is the recursive Folders
class.
(Code sample may help)

public class MyContext
{
public Folders Folder
{ get {return null;} } // ignore the return value, this will be filled
later.
}
public class Folders
{
private Folders thisParent;

public Folders()
{
thisParent = this;
}

public Folders Parent
{
get { return thisParent; }
}

public string Name
{
get { return "FolderName "; } // This will return something properly.
}
}
So, with the above, how do I keep track of the .Parent ?

Thanks

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
Jan 16 '07 #1
7 2093
David Colliver wrote:

[...snip...]
I have created a recursive??? function. It looks a little like...

MyContext.Curre nt.Folder.Paren t.Parent.Parent .Parent.Name
This does not look recursive at all; but OTOH this does not look like a
function, too...
As you can see, Parent is the recursive??? part.

Say I start from
/root/Folder1/Folder2/Folder3/Folder4/Folder5, I need to somehow record
where I am in the list, so that when I get to .Name, I see "Folder1".
Pass the name of the current folder as a parameter to your function...
>
Is there an easy way to see how many steps I have taken with Parent to
reach
the folder name?
[...snip...]
Pass the number of steps you took as a parameter to your function...

public something getParentFolder (Folder currentFolder, int stepsTaken)
{
// Your code here...
}

Jan 16 '07 #2
You can pass a parameter that increments with each recursion and is passed
to the next.

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

In case of Minimalism, break Philip Glass.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:99******** *************** ***********@mic rosoft.com...
Hi all,

using C#, .NET 1.1, ASP.NET

I have created a recursive??? function. It looks a little like...

MyContext.Curre nt.Folder.Paren t.Parent.Parent .Parent.Name

As you can see, Parent is the recursive??? part.

Say I start from
/root/Folder1/Folder2/Folder3/Folder4/Folder5, I need to somehow record
where I am in the list, so that when I get to .Name, I see "Folder1".

Is there an easy way to see how many steps I have taken with Parent to
reach
the folder name?

I had thought of using a property, but if I then call another similar
routine later, the property will remain.

I am thinking out loud here... this maybe a solution. Please glance your
eyes over it and let me know if it will work and if there are likely to be
any problems. What I do not know is if I reach the ".Folder", whether the
.Folder routine actually gets called before I run the .Parent, if you see
what I mean.

1. Set up a CurrentFolder property.
2. in .Folder, reset the CurrentFolder property to the actual folder where
we are at, i.e. "/root/Folder1/Folder2/Folder3/Folder4/Folder5"
3. Each time .Parent is called, change the CurrentFolder property to the
new
Folder Path.
4. When Name is called, read off the CurrentFolder.

Will this actually run?

I may have a scope problem here as well...
MyContext is a class that has a "Folder" property, which is based on a
Folders class. The Folders class has "Parent", which is the recursive
Folders
class.
(Code sample may help)

public class MyContext
{
public Folders Folder
{ get {return null;} } // ignore the return value, this will be filled
later.
}
public class Folders
{
private Folders thisParent;

public Folders()
{
thisParent = this;
}

public Folders Parent
{
get { return thisParent; }
}

public string Name
{
get { return "FolderName "; } // This will return something
properly.
}
}
So, with the above, how do I keep track of the .Parent ?

Thanks

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available

Jan 16 '07 #3

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:FB******** *************** ***********@mic rosoft.com...
| Glossary....
|
| Recursion, see recursion.
|

LOL !!!
Jan 16 '07 #4
First of all remeber general rule no. 1.
To understand recurence you must understand recurence!

Użytkownik "David Colliver" <Da***********@ discussions.mic rosoft.com>
napisał w wiadomo¶ci
news:99******** *************** ***********@mic rosoft.com...
Hi all,

using C#, .NET 1.1, ASP.NET

I have created a recursive??? function. It looks a little like...

MyContext.Curre nt.Folder.Paren t.Parent.Parent .Parent.Name

As you can see, Parent is the recursive??? part.

Say I start from
/root/Folder1/Folder2/Folder3/Folder4/Folder5, I need to somehow record
where I am in the list, so that when I get to .Name, I see "Folder1".

Is there an easy way to see how many steps I have taken with Parent to
reach
the folder name?

I had thought of using a property, but if I then call another similar
routine later, the property will remain.

I am thinking out loud here... this maybe a solution. Please glance your
eyes over it and let me know if it will work and if there are likely to be
any problems. What I do not know is if I reach the ".Folder", whether the
.Folder routine actually gets called before I run the .Parent, if you see
what I mean.

1. Set up a CurrentFolder property.
2. in .Folder, reset the CurrentFolder property to the actual folder where
we are at, i.e. "/root/Folder1/Folder2/Folder3/Folder4/Folder5"
3. Each time .Parent is called, change the CurrentFolder property to the
new
Folder Path.
4. When Name is called, read off the CurrentFolder.

Will this actually run?

I may have a scope problem here as well...
MyContext is a class that has a "Folder" property, which is based on a
Folders class. The Folders class has "Parent", which is the recursive
Folders
class.
(Code sample may help)

public class MyContext
{
public Folders Folder
{ get {return null;} } // ignore the return value, this will be filled
later.
}
public class Folders
{
private Folders thisParent;

public Folders()
{
thisParent = this;
}

public Folders Parent
{
get { return thisParent; }
}

public string Name
{
get { return "FolderName "; } // This will return something
properly.
}
}
So, with the above, how do I keep track of the .Parent ?

Thanks

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available

Jan 16 '07 #5

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:99******** *************** ***********@mic rosoft.com...
Hi all,

using C#, .NET 1.1, ASP.NET

I have created a recursive??? function. It looks a little like...

MyContext.Curre nt.Folder.Paren t.Parent.Parent .Parent.Name

As you can see, Parent is the recursive??? part.

Say I start from
/root/Folder1/Folder2/Folder3/Folder4/Folder5, I need to somehow record
where I am in the list, so that when I get to .Name, I see "Folder1".

Is there an easy way to see how many steps I have taken with Parent to
reach
the folder name?

I had thought of using a property, but if I then call another similar
routine later, the property will remain.

I am thinking out loud here... this maybe a solution. Please glance your
eyes over it and let me know if it will work and if there are likely to be
any problems. What I do not know is if I reach the ".Folder", whether the
.Folder routine actually gets called before I run the .Parent, if you see
what I mean.

1. Set up a CurrentFolder property.
2. in .Folder, reset the CurrentFolder property to the actual folder where
we are at, i.e. "/root/Folder1/Folder2/Folder3/Folder4/Folder5"
3. Each time .Parent is called, change the CurrentFolder property to the
new
Folder Path.
4. When Name is called, read off the CurrentFolder.

Will this actually run?

I may have a scope problem here as well...
MyContext is a class that has a "Folder" property, which is based on a
Folders class. The Folders class has "Parent", which is the recursive
Folders
class.
(Code sample may help)

public class MyContext
{
public Folders Folder
{ get {return null;} } // ignore the return value, this will be filled
later.
}
public class Folders
{
private Folders thisParent;

public Folders()
{
thisParent = this;
}

public Folders Parent
{
get { return thisParent; }
}

public string Name
{
get { return "FolderName "; } // This will return something
properly.
}
}
So, with the above, how do I keep track of the .Parent ?
something like

Folders Parent { get { int lastSlash = Name.LastIndexO f('/'); if (lastSlash
< 0) return null; return new Folders(Name.Su bstring(0, lastSlash)); } }
>
Thanks

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available

Jan 16 '07 #6
>So, with the above, how do I keep track of the .Parent ?

something like

Folders Parent { get { int lastSlash = Name.LastIndexO f('/'); if
(lastSlash < 0) return null; return new Folders(Name.Su bstring(0,
lastSlash)); } }
Please note, however, that this won't act properly on paths like:

/root/Folder1/Folder2/Folder3/Folder4/..

because the correct Parent path is /root/Folder1/Folder2, not
/root/Folder1/Folder2/Folder3/Folder4
Jan 16 '07 #7

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:77******** *************** ***********@mic rosoft.com...
Thank you, I will try it.

Your note... Folder4/.. I am assuming you mean that /.. is normally up one
folder (to get to Folder2) where as the code will only get you to Folder4.

That shouldn't be a problem in this case. I am writing a developer tool
and
the function itself should know where it is direct from the system, not
from
developer input.

(To all others who are trying to explain recursion to me. I know what
recursion is. I can do recursion. I just didn't know what to call what I
am
doing, the closest word I could think of was recursion. I commented
earlier
in this thread with an actual recursive function to demonstrate this.)
The proper term would be composition I suspect, as the output from each call
becomes the input to the next. The resulting compiled code is virtually
identical to unrolled iteration so that could be used to describe this as
well.
>
Regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Ben Voigt" wrote:
>>
>So, with the above, how do I keep track of the .Parent ?

something like

Folders Parent { get { int lastSlash = Name.LastIndexO f('/'); if
(lastSlash < 0) return null; return new Folders(Name.Su bstring(0,
lastSlash)); } }

Please note, however, that this won't act properly on paths like:

/root/Folder1/Folder2/Folder3/Folder4/..

because the correct Parent path is /root/Folder1/Folder2, not
/root/Folder1/Folder2/Folder3/Folder4

Jan 17 '07 #8

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

Similar topics

2
2877
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays a sequence of spaces; recursive function 2 uses input to display ascending sequence of digits; likewise, recursive function 3 uses input to display...
4
2420
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2, opt1=opt1, opt2=opt2, opt3=opt3) return if type(arg2) is ListType:
4
9037
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. However, it is not as straightforward to determine the base address for my stack space. The approach I have taken is to save the address of an automatic...
9
13172
by: Bill Borg | last post by:
Hello, I call a function recursively to find an item that exists *anywhere* down the chain. Let's say I find it five layers deep. Now I've got what I need and want to break out of that whole stack and continue execution at the point of the initial call. Is that possible? Thanks, Bill
9
16801
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script type='text/javascript'> function myFunc(lev) { // if (lev) return myFunc(lev-1); var aStack=; nextFunc = arguments.callee;
41
3328
by: Harry | last post by:
Hi all, 1)I need your help to solve a problem. I have a function whose prototype is int reclen(char *) This function has to find the length of the string passed to it.But the conditions are that no local variable or global variable should be used.I have to use recursive functions.
10
2541
by: AsheeG87 | last post by:
Hello Everyone! I have a linked list and am trying to include a recursive search. However, I am having trouble understanding how I would go about that. I don't quite understand a recursive search....would any of you be so kind to explain it to me...maybe include some examples. I would GREATLY appreciate it!!!
4
2116
by: ThEoNeAnDOnLy | last post by:
I recently had an issue with my recursive project in class. Here is the code. // Recursion.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <conio.h> #include <iostream> using namespace std;
3
4221
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular reference, which means it is only collected by the mark-and-sweep collector, not by reference counting. Here is some code that demonstrates it: ===...
3
2330
by: Davy | last post by:
Hi all, Sometimes I need to pass same parameter in recursive function. From my point of view, the style is redundant, and I don't what to use some global style like self.A, self.B, Is there any other choice? For example, def func(self, x, y, A, B, C): #x, y change in recursive call
0
7520
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...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7470
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...
0
7809
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...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3500
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...
1
1941
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
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.