Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1063197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:44:52+00:00 2026-05-16T18:44:52+00:00

int countNodes( TreeNode *root ) { // Count the nodes in the binary tree

  • 0
int countNodes( TreeNode *root ) {
           // Count the nodes in the binary tree to which
           // root points, and return the answer.
        if ( root == NULL )
           return 0;  // The tree is empty.  It contains no nodes.
        else {
           int count = 1;   // Start by counting the root.
           count += countNodes(root->left);  // Add the number of nodes
                                            //     in the left subtree.
           count += countNodes(root->right); // Add the number of nodes
                                            //    in the right subtree.
           return count;  // Return the total.
        }
     } // end countNodes()

output……..

………..
some thing like this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:44:53+00:00Added an answer on May 16, 2026 at 6:44 pm

    Your question is unclear, so I guess you want to “output data into an XML file”

    Outputing data into a file stream in an XML format could be something like:

    #include <iotream>
    #include <fstream>
    
    int main(int argc, char * argv[])
    {
       TreeNode * root = doWhataverGizmoYouWantToCreateThat() ;
       int count = countNodes(root) ;
       delete root ;
    
       std::fstream output("output.xml", std::ios_base::out)
       output << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" ;
       output << "<count value=\"" << count << "\" />\n" ;
    
       return 0 ;
    }
    

    Please read the iostream help for more information about the fstream object and its uses:

    http://www.cplusplus.com/reference/iostream/

    Now, if you want to parse and modify an existing XML, you’ll need an XML parser. You can google those parsers, for example with:

    http://www.google.com/search?q=XML+c%2B%2B+parser

    Edit:

    After reading the comments :

    XML is a kind of organized text file. Somewhat like HTML, if is about elements, attributes, and data. For example, this is an XML file content:

    <?xml version="1.0" encoding="utf-8" ?>
    <!-- This is a comment -->
    <!-- The first line will declare the XML file, as well as
             its version, and its encoding -->
    <my_element>
    <!-- this is an element. It can contain others elements,
             as well as text data and attributes -->
       <my_other_element my_attribute="some_value" />
       <!-- my_other_element has an attribute whose name is
             my_attribute, and whose value is some_value -->
       <my_another_element>Some text value</my_another_element>
       <!-- my_another_element has an attribute whose content
             is the following text "Some text value" -->
    <my_element>
    <!-- this is the end of my_element, closing it -->
    

    For more information, read :

    http://www.google.com/search?q=XML

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int lf = ((t.left==null) = (t.right==null)) ? 1:0; it returns 1 if the statement
I was wondering how to overload the == operator for a binary tree to
int main(void) { int *a = malloc(10); return 0; } How can I free
int n ; n= (int)( javax.swing.JOptionPane.showInputDialog(null,enter a 3 digit no.)); Why does the above
int test_malloc(void **ptr, size_t size) { (*ptr) = malloc(size); return 0; } int test_app()
int numcells = 2; foreach (System.IO.FileInfo fi in fileQuery) { Label1.Text = fileList.Count().ToString(); TableRow
int n == 0; if (n == null) { Console.WriteLine(......); } Is it true
int* f() { int *p = new int[10]; return p; } int main() {
int main() { char myString = NULL; realloc(&myString, 5); strncpy((char *)&myString, test, 5); }
I was going through the tutorial of binary tree . And I am slightly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.