Actually the subject, the degree of the node is the number of its subtrees 0 or 1 or 2, etc., but I have a binary search tree, respectively, they can not be more than 2!
#include <fstream> #include <iostream> using namespace std; struct tree { int data; tree *left,*right; }; tree *root; void add(int x, tree *&root) { if (!root) { root = new tree; root->data = x; root->left = root->right = NULL; } else if (x < root->data) add(x, root->left); else if (x > root->data) add(x, root->right); } void stepen(int x, tree *root) { if (x->left != NULL && x->right = NULL) cout << "stepen 1\n"; if (x->left == NULL && x->right != NULL) cout << "stepen 1\n"; if (x->left != NULL && x->right != NULL) cout << "stepen 2\n" ; } void deletet(tree *&root) { if (root) { delete(root->left); delete(root->right); delete root; root = NULL; } } void print(tree *root) { if (root) { if (root->left == NULL && root->right == NULL) cout << root->data << ' '; else { print(root->left); print(root->right); } } } int main() { ifstream in("input.txt"); int x; while (in.peek() != EOF) { in >> x; add(x, root); } print(root); cout << endl; stepen(6, root); cout << endl; deletet(root); in.close(); system("pause"); return 0; }