home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / CLASSINC.ZIP / PRIORTYQ.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.6 KB  |  120 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  PRIORTYQ.H                                                            */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1992                            */
  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. #pragma option -Vo-
  22. #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  23. #pragma option -po-
  24. #endif
  25.  
  26. _CLASSDEF(PriorityQueue)
  27.  
  28. class _CLASSTYPE PriorityQueue :
  29.     public Container,
  30.     public virtual TShouldDelete
  31. {
  32.  
  33. public:
  34.  
  35.     int isEmpty() const
  36.         {
  37.         return tree.isEmpty();
  38.         }
  39.  
  40.     countType getItemsInContainer() const
  41.         {
  42.         return tree.getItemsInContainer();
  43.         }
  44.  
  45.     void put(Object& o)
  46.         {
  47.         tree.add(o);
  48.         }
  49.  
  50.     Object& get()
  51.         {
  52.         if( isEmpty() )
  53.             return NOOBJECT;
  54.         else
  55.             {
  56.             Object& obj = tree[0];
  57.             tree.detach( obj ); // does not delete
  58.             return obj;
  59.             }
  60.         }
  61.  
  62.     Object& peekLeft()
  63.         {
  64.         return (isEmpty()?NOOBJECT:tree[0]);
  65.         }
  66.  
  67.     void detachLeft( DeleteType dt = NoDelete )
  68.         {
  69.         if( !isEmpty() )
  70.             tree.detach( tree[0], dt );
  71.         }
  72.  
  73.     void flush( DeleteType dt = DefDelete )
  74.         {
  75.         tree.flush( dt );
  76.         }
  77.  
  78.     int hasMember( Object& obj ) const
  79.         {
  80.         return tree.hasMember( obj );
  81.         }
  82.  
  83.     int ownsElements()
  84.         {
  85.         return tree.ownsElements();
  86.         }
  87.  
  88.     void ownsElements( int del )
  89.         {
  90.         tree.ownsElements( del );
  91.         }
  92.  
  93.     virtual classType isA() const
  94.         {
  95.         return priorityQueueClass;
  96.         }
  97.  
  98.     virtual char _FAR *nameOf() const
  99.         {
  100.         return "PriorityQueue";
  101.         }
  102.  
  103.     virtual ContainerIterator _FAR & initIterator() const
  104.         {
  105.         return tree.initIterator();
  106.         }
  107.  
  108. private:
  109.  
  110.     Btree tree;
  111.  
  112. };
  113.  
  114. #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  115. #pragma option -po.
  116. #endif
  117. #pragma option -Vo.
  118.  
  119. #endif
  120.