#include<bits/stdc++.h>
using namespace std;
struct node
{
int num,next,id;
};
void nextmax(int n)
{
stack<struct node>s;
struct node a[100050],t;
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i].num);
a[i].next=-1;
a[i].id=i;
if(s.empty())
s.push(a[i]);
else
{
while(!s.empty())
{
t=s.top();
if(a[i].num>t.num)
{
a[t.id].next=a[i].num;
s.pop();
}
else
break;
}
s.push(a[i]);
}
}
for(int i=1; i<=n; i++)
printf("%d-->%d\n",a[i].num,a[i].next);
}
int main()
{
int n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
nextmax(n);
if(T)printf("\n");
}
return 0;
}
SDUT3333&&SDUT3332数据结构实验之栈五:下一较大值(一)
最新推荐文章于 2022-10-22 08:54:48 发布