nodelist.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "nodelist.h"
  2. void nodelist_init(nodelist_t nodelist)
  3. {
  4. nodelist->head=0;
  5. nodelist->tail=0;
  6. }
  7. void nodelist_push_back(nodelist_t nodelist, queue_node_t *item)
  8. {
  9. if (!nodelist->head)
  10. {
  11. nodelist->head=item;
  12. nodelist->tail=item;
  13. }
  14. else
  15. {
  16. nodelist->tail->Next=item;
  17. nodelist->tail=item;
  18. }
  19. item->Next = 0;
  20. }
  21. void nodelist_push_front(nodelist_t nodelist, queue_node_t *item)
  22. {
  23. if (!nodelist->head)
  24. {
  25. nodelist->head=item;
  26. nodelist->tail=item;
  27. item->Next=0;
  28. }
  29. else
  30. {
  31. item->Next = nodelist->head;
  32. nodelist->head = item;
  33. }
  34. }
  35. queue_node_t *nodelist_pop_front(nodelist_t nodelist)
  36. {
  37. queue_node_t *ret;
  38. if (!nodelist->head)
  39. return 0;
  40. ret = nodelist->head;
  41. nodelist->head = nodelist->head->Next;
  42. ret->Next = 0; // so we don't confuse anyone
  43. if (ret == nodelist->tail)
  44. {
  45. nodelist->tail = 0;
  46. }
  47. return ret;
  48. }
  49. void nodelist_push_back_list(nodelist_t nodelist, queue_node_t *item)
  50. {
  51. if (!nodelist->head)
  52. {
  53. nodelist->head=item;
  54. }
  55. else
  56. {
  57. nodelist->tail->Next=item;
  58. }
  59. while (item->Next)
  60. item = item->Next;
  61. nodelist->tail = item;
  62. }