Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ALGO(T,P)
- flag= 0
- ret= 0
- if T != NIL then
- if T->key % 2 = 0 then
- flag= 1
- x= ALGO(T->sx, T)
- y= ALGO(T->dx, T)
- if flag=1 AND P != NIL AND x+y=0 then
- if P->sx= T then
- P->sx= CANCELLA-ROOT(T)
- else
- P->dx= CANCELLA-ROOT(T)
- ret= x+y+flag
- return ret
- */
- ALGO_IT(T, P)
- currT= T, currP= P, last=nextT=nextP= NIL
- ret=flag=0
- S_T= S_P= S_flag= S_x= NIL
- while (currT != NIL || S_T != NIL) do
- if (currT != NIL) then
- ret= 0
- flag= 0
- if (currT->key % 2 == 0) then
- flag= 1
- push(S_T, currT)
- push(S_P, currP)
- push(S_flag, flag)
- nextT= currT->sx
- nextP= currT
- else
- currT= top(S_T)
- currP= top(S_P)
- flag= top(S_flag)
- if (last != currT->dx && currT->dx != NIL) then
- x= ret
- push(S_x, x)
- nextT= currT->dx
- nextP= currT
- else
- pop(S_T)
- pop(S_P)
- pop(S_flag)
- x= top(S_x)
- pop(S_x)
- if (currT->dx != NIL) then
- y= ret
- else
- y= 0
- if (flag == 1 && currP != NIL && x+y= 0) then
- if (currP->sx == currT) then
- currP->sx= CANCELLA-ROOT(currT)
- else
- currP->dx= CANCELLA-ROOT(currT)
- ret= x+y+flag
- nextT= NIL
- last= currT
- currT= nextT
- currP= nextP
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement