home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / LIST2.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  746 b   |  24 lines

  1. // list2.h:   A Integer List Class
  2. // from Chapter 6 of Getting Started
  3. const int Max_elem = 10;
  4.  
  5. class List
  6. {
  7. protected:     // The protected keyword gives subclasses
  8.                // direct access to inherited members
  9.    int *list;        // An array of integers
  10.    int nmax;         // The dimension of the array
  11.    int nelem;        // The number of elements
  12.  
  13. public:
  14.    List(int n = Max_elem) {list = new int[n]; nmax = n; nelem = 0;};
  15.    ~List() {delete list;};
  16.    int put_elem(int, int);
  17.    int get_elem(int&, int);
  18.    void setn(int n) {nelem = n;};
  19.    int getn() {return nelem;};
  20.    void incn() {if (nelem < nmax) ++nelem;};
  21.    int getmax() {return nmax;};
  22.    virtual void print();                   // line 22
  23. };
  24.