 |
|
 |
Hello,
I am pretty new in object oriented programming and having trouble with tree data structure. I am trying to add new children to children.I mean trying to advance my tree. What is the problem with this usage and what is its solution?
char *temp;
CTreeCountry,Washington,WhiteHouse;
Country.item.name="USA"; Washington.item.name="Washington"; WhiteHouse.item.name="White House"; Country.children.push_back(&Washington); Washington.children.push_back(&WhiteHouse);//Adding new children to a children
temp=new char(WhiteHouse.item.name.size());
//strcpy(temp,Washington->children[0]->item->name.c_str());//PROBLEM //strcpy(temp,Washington.children[0].item.name.c_str()); //PROBLEM
Any help would be appreciated...
And the other thing is how can I find the parent of a children?
Thank you for your interest
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I understood this part
//strcpy(temp,Washington->children[0]->item->name.c_str());//PROBLEM //strcpy(temp,Washington.children[0].item.name.c_str()); //PROBLEM
the correct one should be; strcpy(temp,Washington.children[0]->item.name.c_str());//since children take pointers
But if you give me some example about how to traverse this tree any additional method to this simple tree class, how to find the parent of a node etc., it would be appreciated...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
This article could be of value if you were to offer more information about your idea (e.g. why is your idea a better choice for doing something than what already exist). Then follow that with an explanation (and sample code) to support your reason for believing that to be the case. When the person reading your article has finished doing so, he/she should have no doubt that what you have just offered, is indeed superior to what already exist, or widely known.
To find out how you'd go about determining when something is "widely known" might require a little research on your side, which in the end might even convince you that more work has to be done on the article you propose submitting.
I gave you a '3' for it being your first article. Shoot for a '5' with your next one.
William
Fortes in fide et opere!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you for your reply. My idea was to show the easiest and fastest way to create a tree structure using STL vector template.
Sometimes it is not very clear how to create a tree structure using STL (as far as I know there is no simple STL tree template).
I wanted to share my idea how to do this.
|
| Sign In·View Thread·PermaLink | 3.67/5 (2 votes) |
|
|
|
 |
|
 |
Your wanting to share your idea about something with the community, or how to do something, is noble. That is what CodeProject is all about, but there is a standard of excellence which you as an individual must also demonstrate (which is why a lot of members BEFORE submitting an article to CodeProject, will first check things out right here on CodeProject, to see if something similar already exist or to see what other writers may have done on the subject).
Nobody expects you to write about, or submit an idea on the next "Killer App", which (who knows) you may very well do. But the point is, by researching right here on CodeProject, you could come away with a pretty good idea on what it takes to write a good article.
Granted, the STL doesn't (at this time) have an algorithm for creating tree structures, but that doesn't mean you should submit an article on the subject if it's not going to be really good! After all, for something that doesn't exist right now, and for which you are going to introduce the first of its kind, that alone should tell you that it better be good.
Just chuck this one up to experience and shoot for a '5' with your next article. You have the "right stuff"; it just needs a little polishing up. Here's to your success!
William
Fortes in fide et opere!
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
 |
You understood me really good. I have some code and solutions to share with cominity and I had to start with something.
May be this article was really worthless, who knows... I remembered myself trying to create a simple tree, searching the web for comments and solutions... Maybe I could help someone... Who knows...
Thank you very much for your politeness and understanding.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sometimes just bringing attention to a topic is pretty good. It would also be good for naysayers to improve the article instead of just saying it falls short. It's always easier to complain than actually do something.
Anyway, a typical thing is that a tree needs to hold different types of items at various levels, but all those types (except maybe the ones used for node items) need to inherit from the tree-type so that they can have children.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
I'm sorry to say this, but this article is worthless. We already know how to define a class. It is ridiculous to say "this class can be extended". Not only is that statement obvious, but it should be you who extends the class and you who includes decent functionality. Your code, such as it is, completely ingores all the issues involved with parent-child trees.
I have no idea how anyone could justify posting useless articles like this - it neither presents usable code or a tutorial.
Another article that deserves lower than 1 out of 5
|
| Sign In·View Thread·PermaLink | 1.67/5 (3 votes) |
|
|
|
 |
|
 |
I agree, it's wothless... A better choise is to use heavy tree structures to implement simple things...
|
| Sign In·View Thread·PermaLink | 4.00/5 (3 votes) |
|
|
|
 |
|
 |
Pavel Molchanov wrote: heavy tree structures
What are you talking about? Clearly you cannot defend this rubbish. It seems that not only are you inexperienced, you are also arrogant.
|
| Sign In·View Thread·PermaLink | 1.33/5 (3 votes) |
|
|
|
 |
|
 |
but we can impove on the time effiiency of the code..but dont u feel we need to make user friendly easy comprehendable codes....
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I agree - this was a complete waste of time to read, and totally worthless. I wish code project would filter out this sort of stuff.
|
| Sign In·View Thread·PermaLink | 1.56/5 (5 votes) |
|
|
|
 |
|
|
 |