Please convert the code in C language   #include using namespace std; // tree node is defined class tree{         public:         int data;         tree *left;         tree *right; }; void printSibling(tree* root) {     //Declare queue using STL      queue q;     //enqueue the root     q.push(root);     vector store;     tree* temp;     //do the level order traversal & check for siblings     while(!q.empty()){         //dequeue         temp=q.front();         q.pop();         //if the current node has only one child          //definitely the child has no sibling         //store the child node value         if(temp->left==NULL && temp->right!=NULL){             store.push_back(temp->right->data);         }         if(temp->left!=NULL && temp->right==NULL){             store.push_back(temp->left->data);         }         // do level order traversing         if(temp->right)             q.push(temp->right);         if(temp->left)             q.push(temp->left);     }     //if no node found without having sibling     //vector size is zero     //print -1     if(store.size()==0){         printf("-1, no such  node\n");     return;     }     //sort the vector to print sorted node value     sort(store.begin(),store.end());     //printing     for(auto it=store.begin();it!=store.end();it++)         printf("%d ",*it); } tree* newnode(int data)  // creating new node {      tree* node = (tree*)malloc(sizeof(tree));      node->data = data;      node->left = NULL;      node->right = NULL;      return(node);  }  int main()  {      //**same tree is builted as shown in example**     cout<<"same tree is built as shown in example\n";     tree *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 in C language

 

#include <bits/stdc++.h>
using namespace std;

// tree node is defined
class tree{    
    public:
        int data;
        tree *left;
        tree *right;
};

void printSibling(tree* root)
{
    //Declare queue using STL 
    queue<tree*> q;
    //enqueue the root
    q.push(root);
    vector<int> store;

    tree* temp;
    //do the level order traversal & check for siblings
    while(!q.empty()){
        //dequeue
        temp=q.front();
        q.pop();
        //if the current node has only one child 
        //definitely the child has no sibling
        //store the child node value
        if(temp->left==NULL && temp->right!=NULL){
            store.push_back(temp->right->data);
        }

        if(temp->left!=NULL && temp->right==NULL){
            store.push_back(temp->left->data);
        }
        // do level order traversing
        if(temp->right)
            q.push(temp->right);
        if(temp->left)
            q.push(temp->left);
    }
    //if no node found without having sibling
    //vector size is zero
    //print -1
    if(store.size()==0){
        printf("-1, no such  node\n");
    return;
    }
    //sort the vector to print sorted node value
    sort(store.begin(),store.end());
    //printing
    for(auto it=store.begin();it!=store.end();it++)
        printf("%d ",*it);
}

tree* newnode(int data)  // creating new node

    tree* node = (tree*)malloc(sizeof(tree)); 
    node->data = data; 
    node->left = NULL; 
    node->right = NULL; 

    return(node); 


int main() 

    //**same tree is builted as shown in example**
    cout<<"same tree is built as shown in example\n";
    tree *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; 
    printSibling(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 2 steps with 1 images

Blurred answer
Knowledge Booster
Types of trees
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