stack algorithm is working