Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 19-02-19 Traccia A
- AlgoIT(A,x,y,k)
- STZ=STY=ST_VAL=ST_A=LAST=NIL
- CX=X, CY=Y
- while(cx<=cy || sty!=NIL)do
- if(cx<=cy)then
- val=0
- z=cx+cy/2
- if(A[z]==k)then
- val=1
- STY=push(STY,cy)
- STZ=push(STZ,z)
- ST_VAL=push(ST_VAL,val)
- cy=z-1
- else
- cy=top(STY); z=top(STZ); val=top(ST_VAL)
- if(last!=cy)then
- a=val
- if(a>val)then
- val=a+val
- pop(ST_VAL)
- ST_VAL=push(ST_VAL,val)
- STA=push(STA,a)
- cx=z+1
- else
- b=val //da non confondere con l'altro val, questo รจ il ritorno della chiamata ricorsiva (il ritorno ret)
- val=val+top(STA)+b
- last=cx
- cx=cy+1
- pop(STA,ST_VAL,STY,STZ)
- ret=val
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement