home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / pgmutl / val_link.arc / LIST.C < prev    next >
Text File  |  1989-02-18  |  5KB  |  142 lines

  1. /*                                 LIST.C                                  */
  2.  
  3. /*+-------------------------------------------------------------------------+
  4.   |                                                                         |
  5.   |                               ListDelete                                |
  6.   |                                                                         |
  7.   +-------------------------------------------------------------------------+*/
  8. void ListDelete(Generic_Element_ptr       elem,
  9.                 Generic_Element_list far *lst)
  10. BeginDeclarations
  11. #define Elem                           (*elem)
  12. #define Lst                            (*lst)
  13. Generic_Element_ptr                    current;
  14. #define Current                        (*current)
  15. Generic_Element_ptr                    prior;
  16. #define Prior                          (*prior)
  17. EndDeclarations
  18. BeginCode
  19.  prior = Null;
  20.  TraverseList(Lst, current)
  21.   BeginTraverse
  22.    If current Is elem
  23.     Then
  24.      If prior Is Null
  25.       Then
  26.        First(Lst) = Elem.next;
  27.        If First(Lst) Is Null
  28.         Then
  29.          Last(Lst) = Null;
  30.         EndIf;
  31.       Else
  32.        Prior.next = Elem.next;
  33.        If Last(Lst) Is elem
  34.         Then
  35.          Last(Lst) = prior;
  36.         EndIf;
  37.       EndIf;
  38.      ExitLoop;
  39.     EndIf;
  40.    prior = current;
  41.   EndTraverse;
  42.  return;
  43. EndCode
  44. #undef Elem
  45. #undef Lst
  46. #undef Current
  47. #undef Prior
  48.  
  49. /*+-------------------------------------------------------------------------+
  50.   |                                                                         |
  51.   |                           ListInsert                                    |
  52.   |                                                                         |
  53.   +-------------------------------------------------------------------------+*/
  54. void ListInsert(Generic_Element_ptr       elem,
  55.                 bit_16                    type_insert,
  56.                 Generic_Element_ptr       aftr,
  57.                 Generic_Element_list far *lst)
  58. BeginDeclarations
  59. #define Elem                           (*elem)
  60. #define Aftr                           (*aftr)
  61. #define Lst                            (*lst)
  62. EndDeclarations
  63. BeginCode
  64.  Using type_insert
  65.   BeginCase
  66. /*+-------------------------------------------------------------------------+
  67.   |                                                                         |
  68.   |  Handle:   Insert ptr After aftr InList lst EndInsert;                  |
  69.   |                                                                         |
  70.   +-------------------------------------------------------------------------+*/
  71.    When 0:
  72.     Elem.next  = Aftr.next;
  73.     Aftr.next  = elem;
  74.     If Elem.next IsNull
  75.      Then
  76.       Last(Lst) = elem;
  77.      EndIf;
  78.     break;
  79. /*+-------------------------------------------------------------------------+
  80.   |                                                                         |
  81.   |  Handle:   Insert ptr AtEnd InList lst EndInsert;                       |
  82.   |                                                                         |
  83.   +-------------------------------------------------------------------------+*/
  84.    When 1:
  85.     If Last(Lst) IsNull
  86.      Then
  87.       First(Lst) = elem;
  88.      Else
  89.       (*Last(Lst)).next = elem;
  90.      EndIf;
  91.     Last(Lst)  = elem;
  92.     Elem.next  = Null;
  93.     break;
  94. /*+-------------------------------------------------------------------------+
  95.   |                                                                         |
  96.   |  Handle:   Insert ptr AtBeginning InList lst EndInsert;                 |
  97.   |                                                                         |
  98.   +-------------------------------------------------------------------------+*/
  99.    When 2:
  100.     Elem.next  = First(Lst);
  101.     First(Lst) = elem;
  102.     If Last(Lst) IsNull
  103.      Then
  104.       Last(Lst) = elem;
  105.      EndIf;
  106.     break;
  107.   EndCase;
  108.  return;
  109. EndCode
  110. #undef Elem
  111. #undef Aftr
  112. #undef Lst
  113.  
  114. /*+-------------------------------------------------------------------------+
  115.   |                                                                         |
  116.   |                                ListPop                                  |
  117.   |                                                                         |
  118.   +-------------------------------------------------------------------------+*/
  119. void ListPop(Generic_Element_list far *lst,
  120.              Generic_Element_ptr      *elem)
  121. BeginDeclarations
  122. #define Elem                           (*elem)
  123. #define Lst                            (*lst)
  124. EndDeclarations
  125. BeginCode
  126.  If First(Lst) IsNull
  127.   Then
  128.    Elem = Null;
  129.    return;
  130.   EndIf;
  131.  Elem       = First(Lst);
  132.  First(Lst) = (*Elem).next;
  133.  If First(Lst) IsNull
  134.   Then
  135.    Last(Lst) = Null;
  136.   EndIf;
  137.  return;
  138. EndCode
  139. #undef Elem
  140. #undef Lst
  141.  
  142.