, чтобы сохранить scanf в функции вставки, вы хотите сделать флаг, чтобы знать, инициализируете ли вы переменные (идентификатор и зарплату) впервые или у вас уже есть значения и вы не хотите снова сканировать.
#include <stdio.h>
#include <stdlib.h>
struct Node{
int EmployeeID;
float Salary;
struct Node* left;
struct Node* right;
};
struct Node* insert(struct Node* root,int ID, float Salary){
if(ID==-1 && Salary==-1)
{
printf("Enter Employee ID: ");
scanf("%d", &ID);
printf("Enter Employee Salary: ");
scanf("%f", &Salary);
}
if(root == NULL){
root = (struct Node*)malloc(sizeof(struct Node));
root->EmployeeID = ID;
root->Salary = Salary;
root->left=NULL;
root->right= NULL;
}
else if(ID < root->EmployeeID)
root->left = insert(root->left, ID, Salary);
else
root->right = insert(root->right, ID, Salary);
return root;
};
void PrePrint(struct Node* root){
if(root == NULL)
return;
printf("%d %.2f\n", root->EmployeeID, root->Salary);
PrePrint(root->left);
PrePrint(root->right);
return;
}
int main()
{
int N, i;
struct Node* root;
int ID;
float Salary;
root = NULL;
printf("How many Employee you would like to enter? \n");
scanf("%d", &N);
for(i=0; i<N; i++){
root = insert(root, ID=-1, Salary=-1);
printf("\n");
}
PrePrint(root);
}