Ejemplo n.º 1
0
 void
 print()
 {
   if (l != NULL)
     l->print();
   cout << el->f() << " " << s << "\n";
   if (r != NULL)
     r->print();
 }
Ejemplo n.º 2
0
  void
  add(element<T>* e)
  {
    s++;
    if (this->l == NULL)
      {
	if (el->f() > e->f())
	  {
	    l = new heap(el);
	    l->p = this;
	    l->el->root = l;
	    el = e;
	    el->root = this;
	  }
	else
	  {
	    l = new heap(e);
	    l->p = this;
	    l->el->root = l;
	  }
      }
    else if (r == NULL)
      {
	if (el->f() > e->f())
	  {

	    r = new heap(el);
	    r->p = this;
	    r->el->root = r;
	    el = e;
	    this->el->root = this;
	  }
	else
	  {
	    r = new heap(e);
	    r->p = this;
	    r->el->root = r;
	  }
      }
    else if (l->s > r->s)
      {
	if (el->f() > e->f())
	  {
	    r->add(el);
	    el = e;
	    this->el->root = this;
	  }
	else
	  {
	    r->add(e);
	  }
      }
    else
      {
	if (el->f() > e->f())
	  {
	    l->add(el);
	    el = e;
	    this->el->root = this;
	  }
	else
	  {
	    l->add(e);
	  }
      }
  }