do
{
pop(&s,&q);
if (!empty(&s))
rightpointer = right(item(&s));
else
rightpointer = null;
}while(!empty(&s)&&(q==rightpointer));