home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-3.ZIP / EXAMPLES.ZIP / LIST.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  727b  |  35 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // list.cpp:   Implementation of the List Class
  4. // from Hands-on C++
  5. #include <iostream.h>
  6. #include "list.h"
  7.  
  8. int List::put_elem(int elem, int pos)
  9. {
  10.    if (0 <= pos && pos < nmax)
  11.    {
  12.       list[pos] = elem;    // Put an element into the list
  13.       return 0;
  14.    }
  15.    else
  16.       return -1;           // Non-zero means error
  17. }
  18.  
  19. int List::get_elem(int& elem, int pos)
  20. {
  21.    if (0 <= pos && pos < nmax)
  22.    {
  23.       elem = list[pos];    // Retrieve a list element
  24.       return 0;
  25.    }
  26.    else
  27.       return -1;           // non-zero means error
  28. }
  29.  
  30. void List::print()
  31. {
  32.    for (int i = 0; i < nelem; ++i)
  33.       cout << list[i] << "\n";
  34. }
  35.