/*
 * Simple singly-linked list class & templates
 * Implementation file
 * $Id: list.cc,v 1.4 1998/11/24 01:01:36 hsteoh Exp hsteoh $
 */

#include <list.h>                       // prog/lib/ version


/* FUNCTION DEFINITIONS */

_listnode *_listbase::remove(_listiter &pred) {
  _listnode *p;

  if (pred.ptr) {
    p = (_listnode *)((_listnode *)pred.ptr)->next;
    if (p) {				// do nothing if there is no successor
      ((_listnode *)pred.ptr)->next = p->next; // re-link rest of list to pred.
      if (!p->next)			// special case: tail node removed
        bottom=((_listnode *)pred.ptr);
      count--;
    }
  } else {				// remove head of list
    p = (_listnode *)pop();		// pop off top element of list
    if (p) {
      if (!_top) bottom=0;		// last node in list removed
      count--;
    }
  } // endif pred.ptr

  return p;
}

