Home > Articles > Programming > C/C++

Like this article? We recommend

Like this article? We recommend

Removing Items from the Queue

Listing 4 shows the code for removing items from the queue.

Listing 4 Removing Queue Items

const QueueElementPtr NMSServiceQueue::remove(void)
{
  QueueElementPtr tempQueueItem;
  QueueElementPtr nextQueueItem;

  if (queueIsEmpty())
  {
    return NULL;
  }
  else
  {
    tempQueueItem = startOfQueue;
    nextQueueItem = startOfQueue->nextQueueElement;

    if (nextQueueItem != NULL)
      startOfQueue->nextQueueElement = nextQueueItem;

    startOfQueue = tempQueueItem->nextQueueElement;

    return tempQueueItem;
  }
}

As for Listing 3, Listing 4 updates the two variables startOfQueue and endOfQueue in conjunction with items being removed from the queue.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.