Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NELLO STACK: q1,r,q2,ret
- ALGO (A,p,r){
- stq1,stq2,str,stret=NIL;
- cp=p;cr=r;
- lr=NIL;
- ritorno=NIL;
- WHILE (cp<=cr || str !=NIL) DO {
- IF (cp<=cr) THEN
- ret=0;
- IF (cp=cr) THEN
- ret=A[p];
- lr=cr;
- cr=cp-1;
- ritorno=ret;
- ELSE
- q1= ( (cp+2r)/3 );
- stq1=PUSH(stq1,q1);
- str=PUSH(str,cr);
- cr=q1;
- ELSE
- q1=top(stq1);
- cr=top(sr);
- IF (lr!=cr) THEN
- IF (lr=q1) THEN
- ret=ritorno;
- q2= ( (2cp+cr)/3 );
- stq2=PUSH(stq2,q2);
- stret=PUSH(stret,ret);
- cp=q1+1;
- cr=q2;
- ELSE IF (lr=q2) THEN
- q2=TOP(stq2);
- ret=top(stret)+ritorno;
- stret=POP(stret);
- stret=PUSH(stret,ret);
- cp=q2+1;
- ELSE
- ret=top(stret)+ritorno;
- lr=cr;
- cr=cp-1;
- stq1=POP(stq1);
- stq2=POP(stq2);
- str=POP(str);
- stret=POP(stret);
- ritorno=ret;
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement