del.c 521 B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdlib.h>
  2. #include "sllist.h"
  3. static inline void free_nexts(struct sl_list_item* i)
  4. {
  5. struct sl_list_item *tmp = i->next;
  6. while (i->next)
  7. {
  8. tmp = i->next;
  9. i->next = tmp->next;
  10. free(tmp);
  11. }
  12. }
  13. void *sllist_popback(sl_list *list)
  14. {
  15. void *data;
  16. struct sl_list_item *i = list->first;
  17. unsigned int pos = sllist_count(list) -1;
  18. while (pos > SL_LIST_BUFLEN)
  19. {
  20. i = i->next;
  21. pos -= SL_LIST_BUFLEN;
  22. }
  23. data = i->data[pos];
  24. if (pos == 0 && i->next)
  25. free_nexts(i);
  26. list->count--;
  27. return data;
  28. }