spacepaste

  1.  
  2. temp->prev = q->rear;
  3. // allocate a new array for our new item
  4. #if NODE_TYPE == LINKED
  5. if (!q->rear->next) {
  6. q->rear->next = malloc(sizeof(*q->rear->next));
  7. } else {
  8. abort();
  9. }
  10. // update rear->next to point to the new item
  11. q->rear->next = temp;
  12. // update rear to point to the rear->next, which is the item we just added, updating the pointer rear from our old item to our new item
  13. q->rear = q->rear->next;
  14. #elif NODE_TYPE == TREE
  15. struct QNode * p = q->rear;
  16. if (type == NODE_TYPE_BRANCH_CHOICE_START) {
  17. while(p) {
  18. if (p->type == NODE_TYPE_BRANCH_START) {
  19. puts("FOUND BRANCH START");
  20. q->rear = p;
  21. break;
  22. }
  23. if (p->prev) p = p->prev;
  24. else p = NULL;
  25. }
  26. }
  27. // allocate a new array for our new item
  28. if (!q->rear->branch) {
  29. q->rear->branch_count = 1;
  30. q->rear->branch = malloc(sizeof(struct QNode)*q->rear->branch_count);
  31. } else {
  32. q->rear->branch_count++;
  33. q->rear->branch = realloc(q->rear->branch, sizeof(struct QNode)*q->rear->branch_count);
  34. }
  35. // update rear->next to point to the new item
  36. q->rear->branch[q->rear->branch_count-1] = temp;
  37. // update rear to point to the rear->next, which is the item we just added, updating the pointer rear from our old item to our new item
  38. q->rear = q->rear->branch[q->rear->branch_count-1];
  39. #endif
  40.