给定一组数,做成单调递增栈(栈底到栈顶递增),一组数的选择会影响到这个程序
#include<stack>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a[10]={1,5,9,2,4,2,6,10},i;
stack<int>s;
while(!s.empty())
s.pop();
s.push(a[0]);
for(i=1;i<=7;i++)
{
while(a[i]<s.top()&&!s.empty())
s.pop();
s.push(a[i]);
}
while(!s.empty())
{
printf("%d ",s.top());
s.pop();
}
return 0;
}