search along the return path for the next right subtreee at which the traversal is to resume

do

{

pop(&s,&q);

if (!empty(&s))

rightpointer = right(item(&s));

else

rightpointer = null;

}while(!empty(&s)&&(q==rightpointer));