ftech
/SList
(View History)
Singly Linked Lists for classic Mac
Francois Techene Updated "Install" section in README | Amendment 3 on March 31, 2025 |
Name | Last Commit | Last Modified | |
---|---|---|---|
LICENSE | First commit | 2 days ago | |
README | Updated "Install" section in README | 2 days ago | |
slist-test.c | First commit | 2 days ago | |
slist.c | First commit | 2 days ago | |
slist.h | Changed SLISTS_H to SLIST_H in the define section | 2 days ago |
README |
SList: a C library that implements Singly Linked Lists for classic Macintosh programs. SList is free software; see the LICENSE file for copyright/licensing --- # Install This library has been built and tested using THINK C v5 on a Macintosh SE. In order to install it, just import `slist.c` and `slist.h` to your project and include `slist.h` in your source files. --- # Usage ## Creating a new list ``` // Create a new SList object. SList* my_list = SList_new(); ``` ## Adding objects to the list ``` // Append an object at the end of the list. slist_append(my_list, (Ptr)my_object); // Insert an object at a given 0 based index position in the list. // (Third position in this case). slist_insert_at(my_list, (Ptr)my_object, 2); // Insert an object after the first occurence of another one. slist_insert_after(my_list, (Ptr)my_object, (Ptr)other_object); ``` ## Removing objects from the list ``` // Remove the first occurence of an object from the list. slist_remove_value(my_list, (Ptr)my_object); // Remove an object at a given 0 based index postion from the list. // (Third position in this case). slist_remove_at(my_list, 2); // Remove the last object from the list. slist_remove_last(my_list); // Remove all objects from the list. slist_empty(my_list); ``` ## Parsing a list ``` SL_FOREACH(item, list) { obj = (MyObject*)item->data; } ``` You can customize the SL_FOREACH macro by re-implementing `SList.first()`, `SList.last()` and `SList.next()` for your own needs. |