Beispiel #1
0
void List<T>::Merge (List<T>& y )
{
  if (this == &y) return;
  Link * xcurr = head_->next_;   // x = this list
  Link * ycurr = y.head_->next_; // y = that list

  // merge while both lists are not empty
  while (xcurr != tail_ && ycurr != y.tail_)
  {
    if (ycurr->Tval_ < xcurr->Tval_) // y < x
    {
      ycurr = ycurr->next_;
      LinkIn(xcurr,ycurr->prev_);
    }
    else // x <= y
    {
      xcurr = xcurr->next_;
    }
  }

  // splice in remainder of y
  if (ycurr != y.tail_)
  {
    tail_->prev_->next_ = ycurr;
    ycurr->prev_ = tail_->prev_;
    tail_->prev_ = (y.tail_)->prev_;
    (y.tail_)->prev_->next_ = tail_;
  }

  // make y structurally correct for empty
  (y.head_)->next_ = y.tail_;
  (y.tail_)->prev_ = y.head_;
}
Beispiel #2
0
bool List<T>::PushBack (const T& t)
// Insert t at the back (last) position.
{
  Link* newLink = NewLink(t);
  if (newLink == nullptr) return 0;
  LinkIn(tail_,newLink);
  return 1;
}
Beispiel #3
0
bool List<T>::PushFront (const T& t)
// Insert t at the front (first) position.
{
  Link* newLink = NewLink(t);
  if (newLink == nullptr) return 0;
  LinkIn(head_->next_,newLink);
  return 1;
}
Beispiel #4
0
ConstListIterator<T> List<T>::Insert (ConstListIterator<T> i, const T& t)
// Insert t at (in front of) i; return i at new element
{
  if (Empty())  // always insert 
  {
    i = End();
  }
  if (!i.Valid() || i == rEnd()) // null or off-the-front
  {
    std::cerr << " ** cannot insert at position -1\n";
    return End();
  }
  Link* newLink = NewLink(t);
  if (newLink == nullptr) return End();
  LinkIn(i.curr_,newLink);
  // leave i at new entry and return
  i.curr_ = newLink;
  return i;
}
Beispiel #5
0
void LinkRx(int size, int link, void *buf)
{
	int e = LinkIn(size,link,buf,Timeout);
	if( e != 0 )
		IOdebug("LinkRx(%d,%d,%x) error %x",size,link,buf,e);
}