Hi I need some help with this problem Complete the implementation of linear-time algorithm for Stock Span Problem

already I have this code :

```
for i=0 to n-1 do
done < false
while not(D.isEmpty() or done) do
if P[i]>=P[D.top()] then
D.pop()
else
done < true
if D.isEmpty()then
h< -1
else
h <d.top()
S[i]<i-h
D.push(i)
return array S
```