please convert the code toC language
Source Code:
// CPP program for above approach#include using namespace std;// A Binary Tree Nodestruct node{ struct node *left, *right; int data;};// Utility function to// create a new tree nodenode* 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 siblingvoid printSingles(struct node *root){// Base caseif (root == NULL)return;queue q1;q1.push(root);int flag=0;vector v;// While q1 is not emptywhile(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 ordersort(v.begin(), v.end());// Iterate i from 0 to v.size() - 1for (int i = 0; i < v.size();="">{ cout< v[i]="">< "="">}// Check is v is emptyif (v.size() == 0){ cout<>}}// Driver program to test// above functionsint main(){// Let us create binary tree// given in the above example cout<"same tree="" is="" built="" as="" shown="" in="">"same> 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="">"printing><>// Function CallprintSingles(root);return 0;}Output:Extracted text: same tree is built as shown in example printing the nodes that don't have sibling... 4 9
// A Binary Tree Nodestruct node{ struct node *left, *right; int data;};
// Utility function to// create a new tree nodenode* 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 siblingvoid printSingles(struct node *root){
// Base caseif (root == NULL)return;
queue q1;q1.push(root);int flag=0;vector v;// While q1 is not emptywhile(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 ordersort(v.begin(), v.end());// Iterate i from 0 to v.size() - 1for (int i = 0; i < v.size();="">{ cout< v[i]="">< "="">}// Check is v is emptyif (v.size() == 0){ cout<>}}// Driver program to test// above functionsint main(){// Let us create binary tree// given in the above example cout<"same tree="" is="" built="" as="" shown="" in="">"same> 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="">"printing><>// Function CallprintSingles(root);return 0;}Output:Extracted text: same tree is built as shown in example printing the nodes that don't have sibling... 4 9
int flag=0;vector v;// While q1 is not emptywhile(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 ordersort(v.begin(), v.end());// Iterate i from 0 to v.size() - 1for (int i = 0; i < v.size();="">{ cout< v[i]="">< "="">}// Check is v is emptyif (v.size() == 0){ cout<>}}// Driver program to test// above functionsint main(){// Let us create binary tree// given in the above example cout<"same tree="" is="" built="" as="" shown="" in="">"same> 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="">"printing><>// Function CallprintSingles(root);return 0;}Output:Extracted text: same tree is built as shown in example printing the nodes that don't have sibling... 4 9
// While q1 is not emptywhile(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 ordersort(v.begin(), v.end());
// Iterate i from 0 to v.size() - 1for (int i = 0; i < v.size();="">{ cout< v[i]="">< "="">}
// Check is v is emptyif (v.size() == 0){ cout<>}}
// Driver program to test// above functionsint main(){
// Let us create binary tree// given in the above example cout<"same tree="" is="" built="" as="" shown="" in="">"same> 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="">"printing><>// Function CallprintSingles(root);return 0;}
Output:
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here