Next greater element

what is error in my code 2test case not pass

#include
#include

using namespace std;

void next(int *a,int n){

stack<int>s;
stack<int>v;
s.push(0);
int i=1;
for( ;i<n;i++){
 while(!s.empty() && a[s.top()]<a[i]){
    // cout<<a[s.top()]<<","<<a[i]<<endl;
     
     v.push(s.top());
     s.pop();
 }
 while(!v.empty()){
     cout<<a[v.top()]<<","<<a[i]<<endl;
     v.pop();
 }
   if(!s.empty() && a[s.top()]>a[i]){

   
     
    
   }
 
 s.push(i);

}
if(i==n){
    while(!s.empty()){

    
 v.push(s.top());
 s.pop();
}

}
while(!v.empty()){
cout<<a[v.top()]<<","<<"-1"<<endl;
v.pop();
}

}
int main(){

int t;
cin>>t;
while(t–){
long long int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];

   }
   next(a,n);

}
return 0;
}

hi @kumarakash121005
refer this code -->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.