Dijkstra Two-stack algorithm