home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-1.ZIP / CLASSINC.ZIP / PRIORTYQ.H < prev    next >
C/C++ Source or Header  |  1992-02-18  |  2KB  |  110 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  PRIORTYQ.H                                                            */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __PRIORTYQ_H )
  11. #define __PRIORTYQ_H
  12.  
  13. #if !defined( __BTREE_H )
  14. #include "Btree.h"
  15. #endif
  16.  
  17. #if !defined( __SHDDEL_H )
  18. #include <ShdDel.h>
  19. #endif  // __SHDDEL_H
  20.  
  21. _CLASSDEF(PriorityQueue)
  22.  
  23. class _CLASSTYPE PriorityQueue :
  24.     public Container,
  25.     public virtual TShouldDelete
  26. {
  27.  
  28. public:
  29.  
  30.     int isEmpty() const
  31.         {
  32.         return tree.isEmpty();
  33.         }
  34.  
  35.     countType getItemsInContainer() const
  36.         {
  37.         return tree.getItemsInContainer();
  38.         }
  39.  
  40.     void put(Object& o)
  41.         {
  42.         tree.add(o);
  43.         }
  44.  
  45.     Object& get()
  46.         {
  47.         if( isEmpty() )
  48.             return NOOBJECT;
  49.         else
  50.             {
  51.             Object& obj = tree[0];
  52.             tree.detach( obj ); // does not delete
  53.             return obj;
  54.             }
  55.         }
  56.  
  57.     Object& peekLeft()
  58.         {
  59.         return (isEmpty()?NOOBJECT:tree[0]);
  60.         }
  61.  
  62.     void detachLeft( DeleteType dt = NoDelete )
  63.         {
  64.         if( !isEmpty() )
  65.             tree.detach( tree[0], dt );
  66.         }
  67.  
  68.     void flush( DeleteType dt = DefDelete )
  69.         {
  70.         tree.flush( dt );
  71.         }
  72.  
  73.     int hasMember( Object& obj ) const
  74.         {
  75.         return tree.hasMember( obj );
  76.         }
  77.  
  78.     int ownsElements()
  79.         {
  80.         return tree.ownsElements();
  81.         }
  82.  
  83.     void ownsElements( int del )
  84.         {
  85.         tree.ownsElements( del );
  86.         }
  87.  
  88.     virtual classType isA() const
  89.         {
  90.         return priorityQueueClass;
  91.         }
  92.  
  93.     virtual char _FAR *nameOf() const
  94.         {
  95.         return "PriorityQueue";
  96.         }
  97.  
  98.     virtual ContainerIterator _FAR & initIterator() const
  99.         {
  100.         return tree.initIterator();
  101.         }
  102.  
  103. private:
  104.  
  105.     Btree tree;
  106.  
  107. };
  108.  
  109. #endif
  110.