Short programming question Can use any language. Need TONIGHT !!

profiledcwnk

Attached below is an image of an HTML DOM.  This is basically a simple hierarchy of HTML nodes where there are children nodes and sibling nodes (see annotations in the image).

The programming question is to write the body of the function 'countDescendents' shown below.  The example is shown in Java, but you can supply the solution in your programming language of choice.

The Node class is defined as:

public class Node { public Node firstChild; public Node nextSibling;}

The function signature is:

public int countDescendents(Node node) {....}

For example, using the HTML DOM example below, if we passed in the <div id="header_nav"> as the node to countDescendents, the return value would be 9. (div, img, a, ul, li, a, li, a, form).  For the starting node, node.firstChild would be the <div class="avatar"> node, and node.nextSibling would be <div class="inner">.  If a node does not have a firstChild or nextSibling, it'll return null.  You aren't required to include all the logic in the 'countDescendents' function and can create other helper functions as desired.

The countDescendents function should traverse the descendents of the node using only the firstChild and nextSibling attributes of Node.

cid:part1.05040709.08070004@spiceworks.com

 
 

 

 

.

 

    • 11 years ago
    • 20
    Answer(2)

    Purchase the answer to view it

    blurred-text
    NOT RATED
    • attachment
      short_program.docx

    Purchase the answer to view it

    blurred-text
    NOT RATED
    • attachment
      parsermain.zip