Skip to main content
0 online
deanh77 Mar 28, 2001

OK thats not a back pack. You carry it like a briefcase or use the shoulder strap. *You* try strapping an ATX case with power supply and hard drives to your back. hahaha. (OK, that was really la...

iwz Mar 28, 2001

Oh, dean, give me your best guess as to how I wrote the comment threading algorithm on here to work.

deanh77 Mar 28, 2001

(Note: I did not look at your database structure diagram so I assumed some things) OK. Each comment is stored in a database by 'News Item Number' and 'Comment Number' (these two fields compose...

iwz Mar 28, 2001

Hey, that was too hard for me to understand, could you please express your logic in a C++ program? Just kidding. Anyway, wow, Dean! Great job, man. You came very very close to figuring ou...

deanh77 deanh77Founder

ok hmm I gave you the linear "hack" solution. Now here's how I'd do it in Java using objects and recursion.

**************************************************************************

Have a class called Node that contains all comment specific information plus an Enumeration of Node objects (children Nodes). Initially, go through all elements of the table, creating new Node objects with comment specific information, and *initially empty* Child Node List. For simplicity's sake, we have a method called void addNode(Node x) which adds the specified Node to *this* Node's child List. Put these newly created Nodes into a hash table, with hash keyed on comment number.

Oh, I almost forgot. Create a root Node with comment id = -1.

**************************************************************************

One could populate the Node Tree by going through the hash linearly (1,2,3...) and for each Node found, get a reference to its parent from the hash into a variable named "parent", and calling parent.addNode(this); This will give you a Comment node tree.

**************************************************************************

The tree is then printed recursively. printNodeAndChildren(Node rootNode) is called. It (1) prints current Node's info. (2a)(if children exist) for each child x (in Enumeration) calls printNodeAndChildren(x) and returns. (2b)(no children) just returns.

**************************************************************************

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.