home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / os2tk20 / c / samples / tp / ll.cs_ / LL.CSC
Encoding:
Text File  |  1992-07-15  |  2.7 KB  |  112 lines

  1. #   @(#)ll.csc 1.3 1/22/92 16:10:39 [1/26/92] (c)IBM Corp. 1992
  2.  
  3. -- This class is adapted from the book
  4. --   Class Construction in C and C++, Object Oriented Fundamentals
  5. --   by Roger Sessions, Copyright (c) 1992 Prentice Hall.
  6. -- Reprinted with permission.
  7.  
  8. include "bt.sc"
  9.  
  10. class: linkedList,
  11.   local;
  12.  
  13. parent: baseType;
  14.  
  15. /*
  16. ----------------------------------------------------
  17.   Class: linkedList
  18.  
  19. Purpose: A generic linked list class for storing
  20.      heterogenous elements.  Objects of any class
  21.      derived from baseType can be placed on this
  22.      list.
  23. ---------------------------------------------------- */
  24.  
  25.  
  26. passthru: C.h;
  27. #include "bt.h"
  28. #include <stdio.h>
  29. endpassthru;
  30.  
  31. data:
  32.   int max;
  33.   int nlinks;
  34.   link *currentLink;
  35.   link *headLink;
  36.   link *tailLink;
  37.  
  38. methods:
  39.  
  40. group: linkedListMethods;
  41.  
  42.   baseType *llHead();
  43.   -- Make the head of the list the current link, and
  44.   -- return its contents.
  45.  
  46.   baseType *llTail();
  47.   -- Make the tail of the list the current link, and
  48.   -- returns its contents.
  49.  
  50.   int llLength();
  51.   -- Return the number of links is the list.
  52.  
  53.   void llSetMax(int newMax);
  54.   -- Set the maximum number of links the list can contain.
  55.  
  56.   int llLeft();
  57.   -- Return the number of links that can still be added to the
  58.   -- list.
  59.  
  60.   baseType *llNext();
  61.   -- Make the link after current the new current link, and
  62.   -- return its contents.
  63.  
  64.   baseType *llPrevious();
  65.   -- Make the link before current the new current link, and
  66.   -- return its contents.
  67.  
  68.   baseType *llRetrieve();
  69.   -- Return the contents of the current link.
  70.  
  71.   baseType *llReplace(baseType *newElement);
  72.   -- Replace the contents of the current list but this new
  73.   -- element, and return a pointer to the new contents.
  74.  
  75.   baseType *llPromoteTail();
  76.   -- Move the tail link to the head of the list, and return
  77.   -- its contents.
  78.  
  79.   baseType *llAddHead(baseType *newElement);
  80.   -- Add a link containing this new Element to the head of the
  81.   -- list, and return a pointer to the new Element.
  82.  
  83.   baseType *llAddTail(baseType *newElement);
  84.   -- Add a link containing this new Element to the tail of the
  85.   -- list, and return a pointer to the new Element.
  86.  
  87.   baseType *llRemoveHead();
  88.   -- Delete the link at the head of the list.
  89.  
  90.   int llIsTail();
  91.   -- Returns TRUE if the current link is the head of the list,
  92.   -- FALSE otherwise.
  93.  
  94.   void llFreeContents();
  95.   -- Frees the entire list, including the contents of each link.
  96.  
  97.   void llTrace(FILE *output);
  98.   -- Trace the linkedList, useful for debugging.
  99.  
  100. group: BaseOverrides;
  101.  
  102.    override print;
  103.    -- see the baseType defintion for more information.
  104.  
  105. group: SystemMethodOverrides;
  106.  
  107.    override somInit;
  108.  
  109.    override somUninit;
  110.  
  111.    override somDumpSelfInt;
  112.