Блог пользователя ricardogg

Автор ricardogg, история, 5 лет назад, По-английски

Recently, I started learning about Treaps. I watched the Algorithms Live video on youtube and read the cp-algorithms blog on Treaps, however the way they implement the treap is different. I tried reading the code on cp-algorithms and i cannot understand how the split operation works.

void split (pitem t, int key, pitem & l, pitem & r) {
    if (!t)
        l = r = NULL;
    else if (key < t->key)
        split (t->l, key, l, t->l),  r = t;
    else
        split (t->r, key, t->r, r),  l = t;
}

I don't understand how the references to l and r works and how the values are assigned. Is there an easy way to understand how it works?

Thanks in advance. Here is a link to the full tutorial: https://cp-algorithms.com/data_structures/treap.html

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится +18 Проголосовать: не нравится

That code is shit. Nobody understands it.

Just rewrite it so that split() function returns pair<pitem, pitem>