2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Remove a node from a single linked list
9 #include <aros/system.h>
10 #include <proto/arossupport.h>
12 /*****************************************************************************
15 #include <proto/arossupport.h>
24 Remove the node from a single linked list.
27 list - Pointer to the pointer which contains the first element
28 of the single linked list.
29 node - The node which is to be removed.
32 Returns the node if it was in the list.
35 This function is not part of a library and may thus be called
48 24-12-95 digulla created
50 ******************************************************************************/
52 while (*list
&& *list
!= node
)
53 list
= (APTR
*)(*list
);
57 *list
= *((APTR
*)node
);
58 *((APTR
*)node
) = NULL
;
69 /* A single linked list looks like this: */
72 /* No data before this entry ! */
78 struct SNode node1
, node2
;
80 int main (int argc
, char ** argv
)
88 ptr
= RemoveSList ((APTR
*)&List
, &node2
);
90 fprintf (stderr
, "Error: Couldn't find node2\n");
92 printf ("node2 removed.\n");
94 ptr
= RemoveSList ((APTR
*)&List
, &node1
);
96 fprintf (stderr
, "Error: Couldn't find node1\n");
98 printf ("node1 removed.\n");
101 fprintf (stderr
, "Error: List is not empty\n");
103 printf ("List is now empty.\n");