N-Grandparent-Parent-Child Algorithm
-
Greetings, I will try to describe this problem in as much details as I can. Task: Create N HTML page withing a folder-structure based on N grandparent-parent-child relationships. Data structure: TopicID - int ParentTopicID int TopicName - nvarchar(4000) Sample data TopicID ParentTopicID TopicName 0 0 Computers 1 1 Programming 2 1 C# 3 1 C++ 4 1 Java 5 1 Perl 6 0 Operating systems 7 6 Windows 2000 8 6 Windows XP 9 6 Unix Output which to achieve: Folder: Computer File: Computers.html Contents: Programming Operating Systems Folder: Computer/Programming File: Programming.html Contents: C# C++ Java Perl and so forth.... The question is, what is the best algorithm to use to achive the above results? Thank you very much in advanced!
Arsen
-
Greetings, I will try to describe this problem in as much details as I can. Task: Create N HTML page withing a folder-structure based on N grandparent-parent-child relationships. Data structure: TopicID - int ParentTopicID int TopicName - nvarchar(4000) Sample data TopicID ParentTopicID TopicName 0 0 Computers 1 1 Programming 2 1 C# 3 1 C++ 4 1 Java 5 1 Perl 6 0 Operating systems 7 6 Windows 2000 8 6 Windows XP 9 6 Unix Output which to achieve: Folder: Computer File: Computers.html Contents: Programming Operating Systems Folder: Computer/Programming File: Programming.html Contents: C# C++ Java Perl and so forth.... The question is, what is the best algorithm to use to achive the above results? Thank you very much in advanced!
Arsen
Smells a bit like homework...
-
Greetings, I will try to describe this problem in as much details as I can. Task: Create N HTML page withing a folder-structure based on N grandparent-parent-child relationships. Data structure: TopicID - int ParentTopicID int TopicName - nvarchar(4000) Sample data TopicID ParentTopicID TopicName 0 0 Computers 1 1 Programming 2 1 C# 3 1 C++ 4 1 Java 5 1 Perl 6 0 Operating systems 7 6 Windows 2000 8 6 Windows XP 9 6 Unix Output which to achieve: Folder: Computer File: Computers.html Contents: Programming Operating Systems Folder: Computer/Programming File: Programming.html Contents: C# C++ Java Perl and so forth.... The question is, what is the best algorithm to use to achive the above results? Thank you very much in advanced!
Arsen
-
VarChar255 wrote:
The question is, what is the best algorithm to use to achive the above results?
I suggest the critical thinking algorithm. Good luck on your assignment, it's an interesting one.
No not homework at all... actually one of my developers is having trouble with this, he wrote the code but i'd like to get some opinions from others on what patterns they use.
Arsen
-
No not homework at all... actually one of my developers is having trouble with this, he wrote the code but i'd like to get some opinions from others on what patterns they use.
Arsen
VarChar255 wrote:
No not homework at all... actually one of my developers is having trouble with this, he wrote the code but i'd like to get some opinions from others on what patterns they use.
OK, lets flip this around then. What patterns would you use and we'll tell you whether we agree and which of your options sounds like the best way to us! If you're telling the truth, and this really isn't homework, then you'll be willing and able to provide some responses. More likely we will see no response from you whatsoever.
-
VarChar255 wrote:
No not homework at all... actually one of my developers is having trouble with this, he wrote the code but i'd like to get some opinions from others on what patterns they use.
OK, lets flip this around then. What patterns would you use and we'll tell you whether we agree and which of your options sounds like the best way to us! If you're telling the truth, and this really isn't homework, then you'll be willing and able to provide some responses. More likely we will see no response from you whatsoever.
Here is what my developer has implemented (excerpts) void ProcesstopicChildren(DataTable dttopic) { similar while loop, but calling processtopic within whileloop. } main() { DataTable dtChildtopic; DataTable dtParenttopic; ItopicManager topicManager; // this is the SQL connector to call the SQL. int ParenttopicID; ParenttopicID = 8; // Just as a test dtParenttopic = topicManager.GettopicView(ParenttopicID); while(dttopic.Rows.Count > 0) { ParenttopicID = int.Parse(dtParenttopic.Rows[ParenttopicCount]["ParenttopicID"].ToString()); dttopic = topicManager.GettopicView(ParenttopicID); ParenttopicCount++; } }
-
Greetings, I will try to describe this problem in as much details as I can. Task: Create N HTML page withing a folder-structure based on N grandparent-parent-child relationships. Data structure: TopicID - int ParentTopicID int TopicName - nvarchar(4000) Sample data TopicID ParentTopicID TopicName 0 0 Computers 1 1 Programming 2 1 C# 3 1 C++ 4 1 Java 5 1 Perl 6 0 Operating systems 7 6 Windows 2000 8 6 Windows XP 9 6 Unix Output which to achieve: Folder: Computer File: Computers.html Contents: Programming Operating Systems Folder: Computer/Programming File: Programming.html Contents: C# C++ Java Perl and so forth.... The question is, what is the best algorithm to use to achive the above results? Thank you very much in advanced!
Arsen
If the datasource for this is SQL Server 2005, then take a look at using Common Table Expressions (CTE). They will sort this out for you no problem.
Deja View - the feeling that you've seen this post before.