added stack algorithm