Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Algo_it(A,i,j)
- ci=i;
- cj=j;
- last=nil;
- ritorno=nil;
- stack_ret=stack_j=stack_q=stack_i=nil;
- while(ci<cj or stack_j!=nil)do
- if (ci<cj)then
- x=A[ci];
- y=A[j];
- ret=0;
- q=(ci+cj)/2;
- if (i<q)then
- push(stack_q,q);
- push(stack_j,cj);
- cj=q;
- else
- ret=ret+x;
- if (q+1 < j)then
- push(stack_ret,ret);
- push(stack_i,ci);
- ci=q+1;
- else
- ret=ret+y;
- pop(stack_r);
- pop(stack_q);
- pop(stack_ret);
- pop(stack_i);
- last=cj;
- ci=cj+1;
- else
- cj=top(stack_j);
- ci=top(stack_i);
- q=top(stack_q);
- ret=top(stack_ret);
- if(last!=cj)then
- x=ret;
- ritorno=ret+x;
- ret=ritorno;
- if (q+1<j) then
- ci=q+1;
- else
- ritorno=ret+y;
- ret=ritorno;
- pop(stack_r);
- pop(stack_q);
- pop(stack_i)
- pop(stack_ret);
- last=cj;
- ci=cj+1;
- else
- y=ret;
- ritorno=ret+y;
- ret=ritorno;
- pop(stack_r);
- pop(stack_q);
- pop(stack_i)
- pop(stack_ret);
- last=cj;
- ci=cj+1;
- return ret;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement