What could be improved?
Die Implementation von UrnOR::next() kommt mir ein bisschen umständlich/ineffizient vor. Im worst case läuft sie in O(n^2), während ich denke, dass O(n) möglich ist (siehe Vorschlag).
LG!
Do you have a suggestion on how to improve it?
bool UrnOR::next()
{
uint down { m_k };
while (down > 1 && m_balls[down-1] == m_n-1)
{
m_balls[down-1] = 0;
down--;
}
if (down > 0 && m_balls[down-1] < m_n-1)
{
m_balls[down-1]++;
return true;
}
return false;
}
What could be improved?
Die Implementation von UrnOR::next() kommt mir ein bisschen umständlich/ineffizient vor. Im worst case läuft sie in O(n^2), während ich denke, dass O(n) möglich ist (siehe Vorschlag).
LG!
Do you have a suggestion on how to improve it?