You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
758 B

  1. #include "List.h"
  2. void List_append(List *list,IListItem *item) {
  3. item->next = 0;
  4. if ( list->last ) {
  5. list->last->next = item;
  6. } else {
  7. list->first = item;
  8. }
  9. list->last = item;
  10. }
  11. void List_prepend(List *list,IListItem *item) {
  12. item->next = list->first;
  13. list->first = item;
  14. if ( list->last == 0 ) {
  15. list->last = item;
  16. }
  17. }
  18. void List_insert(
  19. List *list,IListItem *item,int (*fn)(IListItem *a,IListItem *b) ) {
  20. IListItem *x;
  21. IListItem *y = 0;
  22. for ( x = list->first; x; y = x, x = x->next ) {
  23. if ( fn( item, x ) ) {
  24. break;
  25. }
  26. }
  27. item->next = x;
  28. if ( x ) {
  29. if ( y ) {
  30. y->next = item;
  31. } else {
  32. list->first = item;
  33. }
  34. } else {
  35. list->first = item;
  36. list->last = item;
  37. }
  38. }