AmendHub

Download: |

ftech

/

SList

 

(View History)


Singly Linked Lists for classic Mac

Francois Techene   Changed license to MIT + refactored to feature camel case syntax.

Name Last Commit Last Modified
LICENSE Changed license to MIT + refactored to feature camel case syntax. 2 days ago
README Changed license to MIT + refactored to feature camel case syntax. 2 days ago
slist-test.c Changed license to MIT + refactored to feature camel case syntax. 2 days ago
slist.c Changed license to MIT + refactored to feature camel case syntax. 2 days ago
slist.h Changed license to MIT + refactored to feature camel case syntax. 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.Lib` from the `build` folder to your project and include it in your source files.

You can also add `slist.c` and `slist.h` directly to your project.
---

# Usage

## Creating a new list
```
// Create a new SList object.
SList* myList = NewSList();
```

## Adding objects to the list
```
// Append an object at the end of the list.
SListAppend(myList, (Ptr)myObject);

// Insert an object at a given 0 based index position in the list.
// (Third position in this case).
SListInsertAt(myList, (Ptr)myObject, 2);

// Insert an object after the first occurence of another one.
SListInsertAfter(myList, (Ptr)myObject, (Ptr)otherObject);
```

## Removing objects from the list
```
// Remove the first occurence of an object from the list.
SListRemoveValue(myList, (Ptr)myObject);

// Remove an object at a given 0 based index postion from the list.
// (Third position in this case).
SListRemoveAt(myList, 2);

// Remove the last object from the list.
SListRemoveLast(myList);

// Remove all objects from the list.
SListEmpty(myList);
```

## 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.