home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 11.ddi / CLASSSRC.ZIP / STACK.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  4.5 KB  |  202 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. }
  87. // End Member Function Stack::push //
  88.  
  89.  
  90. // Member Function //
  91.  
  92. Object& Stack::pop()
  93.  
  94. // Summary -----------------------------------------------------------------
  95. //
  96. //      Pops an object from the stack.
  97. //
  98. // End ---------------------------------------------------------------------
  99. {
  100.     Object& temp = theStack.peekHead();
  101.     theStack.detach( temp );
  102.     return temp;
  103. }
  104. // End Member Function Stack::pop //
  105.  
  106.  
  107. // Member Function //
  108.  
  109. Object& Stack::top() const
  110.  
  111. // Summary -----------------------------------------------------------------
  112. //
  113. //      Peeks at the object on the top of the stack.
  114. //
  115. // End ---------------------------------------------------------------------
  116. {
  117.     return theStack.peekHead();
  118. }
  119. // End Member Function Stack::top //
  120.  
  121.  
  122. // Member Function //
  123.  
  124. int Stack::isEmpty() const
  125.  
  126. // Summary -----------------------------------------------------------------
  127. //
  128. //      Indicates whether the stack is empth
  129. //
  130. // End ---------------------------------------------------------------------
  131. {
  132.     return theStack.isEmpty();
  133. }
  134. // End Member Function Stack::isEmtpy //
  135.  
  136.  
  137. // Member Function //
  138.  
  139. ContainerIterator& Stack::initIterator() const
  140.  
  141. // Summary -----------------------------------------------------------------
  142. //
  143. //      Initializes an iterator for a stack.
  144. //
  145. // End ---------------------------------------------------------------------
  146. {
  147.     return *( (ContainerIterator *)new ListIterator( this->theStack ) );
  148. }
  149. // End Member Function Stack::initIterator //
  150.  
  151. // Member Function //
  152.  
  153. classType Stack::isA() const
  154.  
  155. // Summary -----------------------------------------------------------------
  156. //
  157. //      Returns a predefined value for the class Stack.
  158. //
  159. // Parameters
  160. //
  161. //      none
  162. //
  163. // End ---------------------------------------------------------------------
  164. {
  165.     return stackClass;
  166. }
  167. // End Member Function Stack::isA //
  168.  
  169. // Member Function //
  170.  
  171. char *Stack::nameOf() const
  172.  
  173. // Summary -----------------------------------------------------------------
  174. //
  175. //      Returns the string "Stack".
  176. //
  177. // Parameters
  178. //
  179. //      none
  180. //
  181. // End ---------------------------------------------------------------------
  182. {
  183.     return "Stack";
  184. }
  185. // End Member Function Stack::nameOf //
  186.  
  187.  
  188. // Member Function //
  189.  
  190. hashValueType Stack::hashValue() const
  191.  
  192. // Summary -----------------------------------------------------------------
  193. //
  194. //      Returns the hash value of a stack.
  195. //
  196. // End ---------------------------------------------------------------------
  197. {
  198.     return hashValueType(0);
  199. }
  200. // End Member Function Stack::hashValue //
  201.  
  202.