Why my code giving inorder treaversal

#include
using namespace std;
struct node{
int data;
node* left;
node* right;
};
int sum=0;

node* buildbst(node *root,int data){

if(root==NULL){
root =new node;
root->data=data;
root->left=NULL;
root->right=NULL;
return root;
}
if(data<=root->data){
root->left=buildbst(root->left,data);
}
if(data>root->data){
root->right=buildbst(root->right,data);
}
return root;

}
void modify(node *&root,int &sum){
if(root==NULL){
return;
}
modify(root->right,sum);
sum=root->data+sum;
root->data=sum;
modify(root->left,sum);
}

void PrintPreorder(node* node)
{
if (node == NULL)
return;

cout << node->data << " ";

PrintPreorder(node->left);  


PrintPreorder(node->right); 

}
int main() {

 node *root=NULL;
       int n;
       cin>>n;
       int a[n];
       for(int i=0;i<n;i++){
           cin>>a[i];
           root=buildbst(root,a[i]);}
           int sum=0;
           
           modify(root,sum);
       PrintPreorder(root);
       
    

return 0;

}

@dineshjani hello dinesh can u please share ur code using coding blocks ide as your code is not rendering properly here.

@dineshjani
you code for constructing bst is not correct. you are given inorder traversal of bst and you need to bulild bst from that.
hint - check how to construct bst from inorder trversal array