Пример #1
0
void queue_append(queue* q, queue_element* elem) {
  assert(q != NULL);

  // Need to handle the case where the queue is empty.
  if (queue_is_empty(q)) {
    q->head = queue_new_element(elem);
  } else {
    // Find the last link in the queue.
    queue_link* cur;
    for (cur = q->head; cur->next; cur = cur->next) {}

    // Append the new link.
    cur->next = queue_new_element(elem);
  }
}
Пример #2
0
void queue_append(queue_t q, queue_element_t e) {
    queue_link_t cur;

    assert(q != NULL);

    cur = q->head;
//-----------------------------------------------------------------
//  added case if head is null
//-----------------------------------------------------------------
    if(cur == NULL){
        q->head = queue_new_element(e);
        return;
    }

    while(cur->next) {
        cur = cur->next;
    }

    cur->next = queue_new_element(e);
}
Пример #3
0
void queue_append(queue* q, queue_element* elem) {
  assert(q != NULL);

  queue_element* element = queue_new_element(elem);

  // BUG ONE. If it's empty, set head.
  if (q->head == NULL) {
    q->head = element;
  } else {  // If not empty, set at end.
    // Find the last link in the queue.
    queue_link* cur;
    for (cur = q->head; cur->next; cur = cur->next) {
    }

    // Append the new link.
    cur->next = element;
  }
}