1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
MyObject *pObj; // pointer to an object
LinkedList list; // linked list handle
list = LL_new(); // create new linked list
LL_push(list, NewObject("Foo", 3)); // push a new object onto the list
LL_push(list, NewObject("Bar", 2)); // push a new object onto the list
LL_push(list, NewObject("Cat", 7)); // push a new object onto the list
LL_sort(list, CompareObjects); // sort the list
printf("The list has %d elements\n", // print the list's size
LL_size(list));
LL_foreach(pObj, list) // loop over all elements
PrintObject(pObj);
pObj = LL_shift(list); // shift off the first element
DeleteObject(pObj); // ...and delete it
LL_destroy(list, DeleteObject); // destroy the whole list
|