please convert the code to C language Source Code: // CPP program for above approach #include using namespace std; // A Binary Tree Node struct node { struct node *left, *right; int data; }; // Utility function to // create a new tree node node* newNode(int key) { node *temp = new node; temp->data= key; temp->left = temp->right = NULL; return temp; } // Function to print all // non-root nodes that // don't have a sibling void printSingles(struct node *root) { // Base case if (root == NULL) return; queue q1; q1.push(root); int flag=0; vector v; // While q1 is not empty while(q1.empty() == false) { struct node * temp=q1.front(); q1.pop(); // Check if temp->left is not // NULL and temp->right is NULL if(temp->left != NULL && temp->right == NULL) { flag=1; v.push_back(temp->left->data); } // Check if temp->left is equal // NULL and temp->right is not NULL if(temp->left == NULL && temp->right != NULL) { flag=1; v.push_back(temp->right->data); } // Check if temp->left is not // NULL if(temp->left != NULL) { q1.push(temp->left); } // Check if temp->right is not // NULL if(temp->right != NULL) { q1.push(temp->right); } } // Sort v in increasing order sort(v.begin(), v.end()); // Iterate i from 0 to v.size() - 1 for (int i = 0; i < v.size(); i++) { cout<< v[i] << " "; } // Check is v is empty if (v.size() == 0) { cout<<"-1"; } } // Driver program to test // above functions int main() { // Let us create binary tree // given in the above example cout<<"same tree is built as shown in example\n"; node *root = newNode(2); root->left= newNode(7); root->right= newNode(5); root->right->right=newNode(9); root->right->right->left=newNode(4); root->left->left=newNode(2); root->left->right=newNode(6); root->left->right->left=newNode(5); root->left->right->right=newNode(11); cout<<"printing the nodes that don't have sibling...\n"<

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please convert the code to C language

 

Source Code:

// CPP program for above approach
#include <bits/stdc++.h>
using namespace std;

// A Binary Tree Node
struct node
{
    struct node *left, *right;
    int data;
};

// Utility function to
// create a new tree node
node* newNode(int key)
{
node *temp = new node;
temp->data= key;
temp->left = temp->right = NULL;
return temp;
}

// Function to print all
// non-root nodes that
// don't have a sibling
void printSingles(struct node *root)
{

// Base case
if (root == NULL)
return;

queue<node *> q1;
q1.push(root);

int flag=0;
vector<int> v;

// While q1 is not empty
while(q1.empty() == false)
{
    struct node * temp=q1.front();
    q1.pop();

    // Check if temp->left is not
    // NULL and temp->right is NULL
    if(temp->left != NULL &&
                    temp->right == NULL)
    {
        flag=1;
        v.push_back(temp->left->data);
    }

    // Check if temp->left is equal
    // NULL and temp->right is not NULL
    if(temp->left == NULL &&
                        temp->right != NULL)
    {
        flag=1;
        v.push_back(temp->right->data);
    }

    // Check if temp->left is not
    // NULL
    if(temp->left != NULL)
    {
        q1.push(temp->left);
    }
    
    // Check if temp->right is not
    // NULL
    if(temp->right != NULL)
    {
        q1.push(temp->right);
    }
}

// Sort v in increasing order
sort(v.begin(), v.end());

// Iterate i from 0 to v.size() - 1
for (int i = 0; i < v.size(); i++)
{
    cout<< v[i] << " ";
}

// Check is v is empty
if (v.size() == 0)
{
    cout<<"-1";
}
}

// Driver program to test
// above functions
int main()
{

// Let us create binary tree
// given in the above example
    cout<<"same tree is built as shown in example\n";
    node *root = newNode(2);
    root->left= newNode(7); 
    root->right= newNode(5); 
    root->right->right=newNode(9);
    root->right->right->left=newNode(4);
    root->left->left=newNode(2); 
    root->left->right=newNode(6);
    root->left->right->left=newNode(5);
    root->left->right->right=newNode(11);
    
    cout<<"printing the nodes that don't have sibling...\n"<<endl; 
// Function Call
printSingles(root);
return 0;
}

 

Output:

same tree is built as shown in example
printing the nodes that don't have sibling...
4 9
Transcribed Image Text:same tree is built as shown in example printing the nodes that don't have sibling... 4 9
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Binomial Heap
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education