Object | +---DList | +---DSortedList
The DSortedList class implements a number of methods for using a sorted double linked lists. This class maintains a sorted list. During inserting of objects this list is kept sorted. As a result a number of insert related methods of the parent class DList are disabled and return a warning.
#include <stdio.h> #include "ofc/DSortedList.h" int main(int argc, char *argv[]) { DSortedList *list = [DSortedList alloc]; DText *str; char *names[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; int n; [list init :[DText class] :YES]; // Insert text in sorted list, ascending sorted for (n = 0; n < sizeof(names) / sizeof(names[0]); n++) // Insert the day names, keep them sorted { DText *str = [DText new]; [str set :names[n]]; [list insert :str]; // Insert the string } str = [list join :',']; // Join the list for printing printf("Sorted day names:%s.\n", [str cstring]); [str free]; [list free]; // Cleanup return 0; }