void solve(int n, int a[]) {
stack<int> s;
s.push(a[0]);
for (int i = 1; i < n; i++) {
if (a[i] < s.top()) {
while (!s.empty()) {
cout << s.top() << " ";
s.pop();
}
cout << "\n";
} else {
s.push(a[i]);
cout << "\n";
}
}
}
Here n
is the size of array a[]
.
It doesn't produce any output on console.
example input: a[] = {3, 1, 2}
example expected output:
3
2 1