home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bcpp1611.zip / BCPP / STACKLIS.H < prev   
C/C++ Source or Header  |  1996-12-18  |  3KB  |  114 lines

  1. #ifndef _STACK_LIST_HEADER
  2. #define _STACK_LIST_HEADER
  3.  
  4. // Code written by Steven De Toni ACBC 11
  5. // This header definition contains information of the construction,
  6. // operation of a container class that holds data in linked list
  7. // in stack form.
  8.  
  9. #include <stdio.h>            // NULL Constant
  10. #include "anyobj.h"           // use Base class definition
  11.  
  12.  
  13. // Structure definition used to link the items in the stack
  14. struct ListLink
  15. {
  16.     ListLink*   pLinkedItem;  // linker (pointer to next item in the list)
  17.     ANYOBJECT*  pItem;        // variable used to contain the data
  18. };
  19.  
  20.  
  21. class StackList : public ANYOBJECT
  22. {
  23.     protected:
  24.                               // pointer to the end of the list
  25.             ListLink*     pCurrentPos;
  26.                               // number of items in list
  27.             int           itemCount;
  28.                                   // used to test if memory
  29.         int           spaceAvailable;
  30.         // is still available
  31.     public:
  32.         //#### Constructors
  33.  
  34.         // Initialise internal variables.
  35.         //
  36.         StackList       (void);
  37.  
  38.         // Initalise vaiables, and place item passed in a new list
  39.         //
  40.         // Parameters:
  41.         //     pItem    : Pointer to the object that is will to be stored.
  42.         //                Item must be of desendant ANYOBJECT.
  43.         //
  44.         StackList       (ANYOBJECT* pItem);
  45.  
  46.         //#### Access Methods
  47.         // Places a new item in the list (i.e on the stack).
  48.         //
  49.         // Parameters:
  50.         //     pItem    : Pointer to the object that is will to be stored.
  51.         //                Item must be of desendant ANYOBJECT.
  52.         //
  53.         // Return Values:
  54.         //     int      : Returns a error code value to indicate whether operation
  55.         //                was successful or not.
  56.         //                Value:
  57.         //                0  =  No Worries, item stacked.
  58.         //               -1  =  Item not stacked, memory allocation failure
  59.         //
  60.         int        push            (ANYOBJECT* pItem);
  61.  
  62.         // Removes a item from the list and returns the value contained within it
  63.         // back to the user. A NULL value is returns if there are no more items
  64.         // within the list.
  65.         //
  66.         // Return Values:
  67.         //     ANYOBJECT* : Pointer to the object last object that was placed
  68.         //                  on the stack. Returns NULL pointer if operation
  69.         //                  failed.
  70.         //
  71.         ANYOBJECT* pop             (void);
  72.  
  73.         // Peeks at items within the linked list without removing
  74.         // them from the list.
  75.         //
  76.         // Parameters:
  77.         //    int item :     item number in list.
  78.         //
  79.         // Return Values:
  80.         //   ANYOBJECT*  : Returns NULL if operation failed, else
  81.         //                 pointer to the object contained at list
  82.         //                 number selected!
  83.         //
  84.         ANYOBJECT* peek (int item);
  85.  
  86.         // Returns the number of items current being stacked.
  87.         //
  88.         // Returns Values:
  89.         //     int :    Num of items within queue.
  90.         //
  91.         int        status          (void);
  92.  
  93.         // Method returns whether last operation failed due to memory allocation
  94.         // failure.
  95.         //
  96.         // Return Values:
  97.         //     int  : Returns 1 of two values ...
  98.         //            Values:
  99.         //              0  =  memory available
  100.         //             -1  =  Last memory allocation failed.
  101.         //
  102.         int        space           (void);
  103.  
  104.         //#### Destructor
  105.         // Method will remove all list items from memory if they still exist,
  106.         // no garabage collection provided, or used.
  107.         //
  108.         ~StackList                 (void);
  109. };
  110.  
  111.  
  112. #endif
  113.  
  114.