home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / CLSRC.ZIP / STACK.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  4.6 KB  |  208 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //      Stack::push
  6. //      Stack::pop
  7. //      Stack::top
  8. //      Stack::initIterator
  9. //    Stack::hashValue
  10. //
  11. // Description
  12. //
  13. //      Implementation of class Stack member functions.
  14. //
  15. // End ---------------------------------------------------------------------
  16.  
  17. // Interface Dependencies ---------------------------------------------------
  18.  
  19. #ifndef __IOSTREAM_H
  20. #include <iostream.h>
  21. #define __IOSTREAM_H
  22. #endif
  23.  
  24. #ifndef __CLSTYPES_H
  25. #include <clstypes.h>
  26. #endif
  27.  
  28. #ifndef __OBJECT_H
  29. #include <object.h>
  30. #endif
  31.  
  32. #ifndef __CONTAIN_H
  33. #include <contain.h>
  34. #endif
  35.  
  36. #ifndef __STACK_H
  37. #include <stack.h>
  38. #endif
  39.  
  40. // End Interface Dependencies ------------------------------------------------
  41.  
  42. // Implementation Dependencies ----------------------------------------------
  43.  
  44. #ifndef __LIST_H
  45. #include <list.h>
  46. #endif
  47.  
  48. // End Implementation Dependencies -------------------------------------------
  49.  
  50.  
  51. // Member Function //
  52.  
  53. Stack::~Stack()
  54.  
  55. // Summary -----------------------------------------------------------------
  56. //
  57. //      Destructor for a Stack object.
  58. //
  59. //      We don't do anything here, because the destructor for theStack
  60. //      will destroy all the contained objects.
  61. //
  62. // End ---------------------------------------------------------------------
  63. {
  64. }
  65. // End Destructor //
  66.  
  67.  
  68. // Member Function //
  69.  
  70. void Stack::push( Object& toPush )
  71.  
  72. // Summary -----------------------------------------------------------------
  73. //
  74. //      Pushes the given object on the stack.
  75. //
  76. // Parameters
  77. //
  78. //      toPush
  79. //
  80. //      The object we are to push on the stack.  Once the object is
  81. //      pushed, it is owned by the stack.
  82. //
  83. // End ---------------------------------------------------------------------
  84. {
  85.     theStack.add( toPush );
  86.     itemsInContainer++;
  87. }
  88. // End Member Function Stack::push //
  89.  
  90.  
  91. // Member Function //
  92.  
  93. Object& Stack::pop()
  94.  
  95. // Summary -----------------------------------------------------------------
  96. //
  97. //      Pops an object from the stack.
  98. //
  99. // End ---------------------------------------------------------------------
  100. {
  101.     Object& temp = theStack.peekHead();
  102.     // Ensure there is an object at the top of the stack
  103.     if (temp != NOOBJECT)
  104.     {
  105.         theStack.detach( temp );
  106.         itemsInContainer--;
  107.     }
  108.     return temp;
  109. }
  110. // End Member Function Stack::pop //
  111.  
  112.  
  113. // Member Function //
  114.  
  115. Object& Stack::top() const
  116.  
  117. // Summary -----------------------------------------------------------------
  118. //
  119. //      Peeks at the object on the top of the stack.
  120. //
  121. // End ---------------------------------------------------------------------
  122. {
  123.     return theStack.peekHead();
  124. }
  125. // End Member Function Stack::top //
  126.  
  127.  
  128. // Member Function //
  129.  
  130. int Stack::isEmpty() const
  131.  
  132. // Summary -----------------------------------------------------------------
  133. //
  134. //      Indicates whether the stack is empth
  135. //
  136. // End ---------------------------------------------------------------------
  137. {
  138.     return theStack.isEmpty();
  139. }
  140. // End Member Function Stack::isEmtpy //
  141.  
  142.  
  143. // Member Function //
  144.  
  145. ContainerIterator& Stack::initIterator() const
  146.  
  147. // Summary -----------------------------------------------------------------
  148. //
  149. //      Initializes an iterator for a stack.
  150. //
  151. // End ---------------------------------------------------------------------
  152. {
  153.     return *( (ContainerIterator *)new ListIterator( this->theStack ) );
  154. }
  155. // End Member Function Stack::initIterator //
  156.  
  157. // Member Function //
  158.  
  159. classType Stack::isA() const
  160.  
  161. // Summary -----------------------------------------------------------------
  162. //
  163. //      Returns a predefined value for the class Stack.
  164. //
  165. // Parameters
  166. //
  167. //      none
  168. //
  169. // End ---------------------------------------------------------------------
  170. {
  171.     return stackClass;
  172. }
  173. // End Member Function Stack::isA //
  174.  
  175. // Member Function //
  176.  
  177. char *Stack::nameOf() const
  178.  
  179. // Summary -----------------------------------------------------------------
  180. //
  181. //      Returns the string "Stack".
  182. //
  183. // Parameters
  184. //
  185. //      none
  186. //
  187. // End ---------------------------------------------------------------------
  188. {
  189.     return "Stack";
  190. }
  191. // End Member Function Stack::nameOf //
  192.  
  193.  
  194. // Member Function //
  195.  
  196. hashValueType Stack::hashValue() const
  197.  
  198. // Summary -----------------------------------------------------------------
  199. //
  200. //      Returns the hash value of a stack.
  201. //
  202. // End ---------------------------------------------------------------------
  203. {
  204.     return hashValueType(0);
  205. }
  206. // End Member Function Stack::hashValue //
  207.  
  208.