473,800 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tree built recursive

Hello developers!

I'm sticking in a problem.

I want to read the folder hierarchy of the webserver and store the
information in a tree, built like a linked list - you know 'a tree'.

you see in function readsubtree() i'm storing the object child in the
array of the actualfoldernod e. but this doesn't work out. it never
arrives there.

the tree is just built to one depth. although the recursion works as
some echo outs show.

please help

cheers
a-k

let me post in the snippet:

function readTree(){
global $name_of_root;
$this->rootNode = new FolderTreeNode( $this);
$this->rootNode->name = $name_of_root;
$this->rootNode->absPath = absolutePath("" );
if (relativePath(g etcwd()) == "") {$this->rootNode->selected = true;}
$this->readSubTree(&$ this->rootNode);
}

function readSubTree($ac tualFolderNode) {
$actualAbsDir = $actualFolderNo de->absPath;
$dir = @opendir($actua lAbsDir);
if (!$dir) {return 0;}
while ($entry = readdir($dir)){
if (is_dir($actual AbsDir."/".$entry) && ($entry != ".." && $entry !=
".")){
$child = new FolderTreeNode( $this);
$child->name = $entry;
$child->absPath = $actualAbsDir."/".$entry;
$child->parentNode = $actualFolderNo de;
if (getcwd() == $child->absPath) {$child->selected = true;}
$actualFolderNo de->childNodes[] = $child;
$this->readSubTree($c hild);
}
}
}

class FolderTreeNode{

var $folderTree;

var $name;
var $absPath;
var $parentNode;
var $childNodes = array();
var $selected;
var $newElements;
function FolderTreeNode( $folderTree){
$this->folderTree = $folderTree;
}
}
Jul 16 '05 #1
2 6218
andreas kirschner wrote:
Hello developers!

I'm sticking in a problem.

I want to read the folder hierarchy of the webserver and store the
information in a tree, built like a linked list - you know 'a tree'.

you see in function readsubtree() i'm storing the object child in the
array of the actualfoldernod e. but this doesn't work out. it never
arrives there.

the tree is just built to one depth. although the recursion works as
some echo outs show.

please help

cheers
a-k

let me post in the snippet:

function readTree(){ <snip>
Guess this is OK. }

function readSubTree($ac tualFolderNode) { <snip>
This code looks OK too, except your function declaration needs to pass
the $actualFolderNo de by reference instead of as a regular var.

function readSubTree(&$a ctualFolderNode ) {

unless you're using PHP 5.0, which is supposed to do this automatically.

If you don't pass by reference, $actualFolderNo de is a copy of the
object you're passing into the function, not the actual object itself.
}


Jason

Jul 16 '05 #2
I solved the problem:

the instantiation is now made as a reference as well as the storing in
the childnodes array

function readSubTree(&$a ctualFolderNode ){
$actualAbsDir = $actualFolderNo de->absPath;
$dir = @opendir($actua lAbsDir);
if (!$dir) {return 0;}
while ($entry = readdir($dir)){
if (is_dir($actual AbsDir."/".$entry) && ($entry != ".." && $entry
!= ".")){
$child = &new FolderTreeNode( $this);
$child->name = $entry;
$child->absPath = $actualAbsDir."/".$entry;
$child->parentNode = $actualFolderNo de;
if (getcwd() == $child->absPath) {$child->selected = true;}
$actualFolderNo de->childNodes[] = &$child;
$this->readSubTree($c hild);
}
if (is_file($actua lAbsDir."/".$entry)){
if (strtotime("-".$this->wExplorer->coloredDays. " days") <
(filemtime($act ualAbsDir."/".$entry))) {
$actualFolderNo de->newElements = true;
}
}
}
closedir($dir);
}
Jul 16 '05 #3

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

Similar topics

0
7199
by: t_pet422 | last post by:
Hi, I've been scouring the net and reading the PostgreSQL docs for a while now trying to learn how to create a recursive function in PL/pgSQL that will return a whole subtree given a starting node. I wanted to share my summary results here. Maybe this will help someone and save them from doing a bunch of research (like I had to do :). For the record, this is the first thing I've ever written in PL/pgSQL, although I do have significant...
4
806
by: Jerry Khoo | last post by:
Thanks for the answer, and by the way, i would like to know that in C++, how u create a tree using a recursive envronment. It seems that most people used struct to create a node than, using recursive function to build it up, but than is there any way around i could built a tree using iterative method like for .. loop?
4
2832
by: Henry Jordon | last post by:
I have everything pretty much done but I need to fix something in my coding. I want to be able to enter strings such as "love", "hate", "the", etc. but am unable to figure how to do this. I have put my .cpp and my .h code below. Please help and thank you very much. // include files #ifndef BINTREE_H #define BINTREE_H #include <iostream> #include <iomanip>
12
7000
by: pillepop2003 | last post by:
Hey! Can anyone give me a hint, how this problem is best implemented: I have a table of users (see below), where every user has one "superior user" (= parent node), this should be a fully unambigous tree structure. The root node can have whatever value you prefer, I suppose NULL would be good for a start. What I want to do is finding the way from an arbitrary node in the tree. Example:
13
3883
by: hornedw | last post by:
I have been working on a ecommerce website for myself. What I needed some assistance on was when i was trying to display the categories/subcategories for the different products. I decided to use the modified preorder tree transversal algorithm. What I wanted was on the first page is to display the catogories as follows Books (35) Electronics(23) The number inside the parenthesis being the number of products in that
9
1745
by: Steve Edwards | last post by:
Hi, I have a class which contains a single ptr to another instance which is considered its parent, and an array of ptrs to its children class Nodes{ .... Nodes *mSuper;
15
2689
lwwhite
by: lwwhite | last post by:
I'm not sure if this discussion is a better fit for the Access or XML forum and I don't want to double-post, so I'm starting in Access because you've been so helpful to me here. I am preparing a presentation comparing using a relational database vs. a native XML database within a content management system to manage XML-based documentation. The point I am trying to make is how difficult it can be to reconstruct the XML hierarchy/tree once the...
2
14730
by: aemado | last post by:
I am writing a program that will evaluate expressions using binary trees. Most of the code has been provided, I just have to write the code for the class functions as listed in the header file. However, I am really new to recursion and trees...and this program uses public functions and private helper functions, which I am completely lost in. Here is the header file: struct CTNode { NodeType type; int operand; CTNode *left, *right; };
13
1556
by: Bill Cunningham | last post by:
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);
0
9691
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
9551
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
10505
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
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
10253
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
10035
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...
0
9090
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
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...
1
4149
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.