home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / aros / removeslist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.3 KB  |  123 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: removeslist.c,v 1.4 1997/01/27 00:17:41 ldp Exp $
  4.     $Log: removeslist.c,v $
  5.     Revision 1.4  1997/01/27 00:17:41  ldp
  6.     Include proto instead of clib
  7.  
  8.     Revision 1.3  1996/12/10 13:59:45  aros
  9.     Moved #include into first column to allow makedepend to see it.
  10.  
  11.     Revision 1.2  1996/10/02 16:36:06  digulla
  12.     Fixed a couple of typos in TEST
  13.  
  14.     Revision 1.1  1996/10/02 16:32:58  digulla
  15.     Remove a node from a single linked list
  16.  
  17.     Revision 1.1  1996/08/01 18:46:31  digulla
  18.     Simple string compare function
  19.  
  20.     Desc:
  21.     Lang:
  22. */
  23. #include <aros/system.h>
  24. #include <proto/aros.h>
  25.  
  26. /*****************************************************************************
  27.  
  28.     NAME */
  29. #include <proto/aros.h>
  30.  
  31.     APTR RemoveSList (
  32.  
  33. /*  SYNOPSIS */
  34.     APTR * list,
  35.     APTR   node)
  36.  
  37. /*  FUNCTION
  38.     Remove the node from a single linked list.
  39.  
  40.     INPUTS
  41.     list - Pointer to the pointer which contains the first element
  42.         of the single linked list.
  43.     node - The node which is to be removed.
  44.  
  45.     RESULT
  46.     Returns the node if it was in the list.
  47.  
  48.     NOTES
  49.     This function is not part of a library and may thus be called
  50.     any time.
  51.  
  52.     EXAMPLE
  53.     @atend
  54.  
  55.     BUGS
  56.  
  57.     SEE ALSO
  58.  
  59.     INTERNALS
  60.  
  61.     HISTORY
  62.     24-12-95    digulla created
  63.  
  64. ******************************************************************************/
  65. {
  66.     while (*list && *list != node)
  67.     list = (APTR *)(*list);
  68.  
  69.     if (*list)
  70.     {
  71.     *list = *((APTR *)node);
  72.     *((APTR *)node) = NULL;
  73.  
  74.     return node;
  75.     }
  76.  
  77.     return NULL;
  78. } /* RemoveSList */
  79.  
  80. #ifdef TEST
  81. #include <stdio.h>
  82.  
  83. /* A single linked list looks like this: */
  84. struct SNode
  85. {
  86.     /* No data before this entry ! */
  87.     struct SNode * Next;
  88.     int data;
  89. };
  90.  
  91. struct SNode * List;
  92. struct SNode node1, node2;
  93.  
  94. int main (int argc, char ** argv)
  95. {
  96.     struct SNode * ptr;
  97.  
  98.     List = &node1;
  99.     node1.Next = &node2;
  100.     node2.Next = NULL;
  101.  
  102.     ptr = RemoveSList ((APTR *)&List, &node2);
  103.     if (ptr != &node2)
  104.     fprintf (stderr, "Error: Couldn't find node2\n");
  105.     else
  106.     printf ("node2 removed.\n");
  107.  
  108.     ptr = RemoveSList ((APTR *)&List, &node1);
  109.     if (ptr != &node1)
  110.     fprintf (stderr, "Error: Couldn't find node1\n");
  111.     else
  112.     printf ("node1 removed.\n");
  113.  
  114.     if (List)
  115.     fprintf (stderr, "Error: List is not empty\n");
  116.     else
  117.     printf ("List is now empty.\n");
  118.  
  119.     printf ("End.\n");
  120. }
  121. #endif
  122.  
  123.