home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 412_01 / src / list / listiter.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-28  |  1.3 KB  |  74 lines

  1. #include "list.h"
  2.  
  3. LIST_ITERATOR_::LIST_ITERATOR_(LIST_ &li)
  4. {
  5.     mine = &li;
  6.     current = li.head;
  7. }
  8.  
  9.  
  10. VOBJECT_ *LIST_ITERATOR_::getitem()
  11. {
  12.     return(current ? current->getdata() : NULL);
  13. }
  14.  
  15.  
  16. VOBJECT_ *LIST_ITERATOR_::getfirst()
  17. {
  18.     current = mine->head;
  19.     return(current ? current->getdata() : NULL);
  20. }
  21.  
  22.  
  23. VOBJECT_ *LIST_ITERATOR_::getlast()
  24. {
  25.     current = mine->tail;
  26.     return(current ? current->getdata() : NULL);
  27. }
  28.  
  29.  
  30. VOBJECT_ *LIST_ITERATOR_::getnext() 
  31. {
  32.     if (current == NULL || current->getnext() == NULL)
  33.     return(NULL);
  34.  
  35.     current = current->getnext();
  36.     return(current->getdata());
  37. }
  38.  
  39.  
  40. VOBJECT_ *LIST_ITERATOR_::getprev() 
  41. {
  42.     if (current == NULL || current->getprev() == NULL)
  43.     return(NULL);
  44.  
  45.     current = current->getprev();
  46.     return(current->getdata());
  47. }
  48.  
  49.  
  50. /*                      REMOVE
  51.  
  52.     removes the current node and moves on to the next node, or to the
  53.     previous node if current node is the tail node of the list.
  54.  
  55. */
  56.  
  57. void LIST_ITERATOR_::remove(int dstr)
  58. {
  59.     LIST_NODE_
  60.     *tmp;
  61.  
  62.     if (!current)
  63.     return;
  64.  
  65.     if (current == mine->tail)
  66.     tmp = current->getprev();
  67.     else
  68.     tmp = current->getnext();
  69.  
  70.     mine->remove_node(current, dstr);
  71.     current = tmp;
  72. }
  73.  
  74.