Q: C Queue, Duplicating elements in sorted order So 
if I have a queue 
a --> b --> NULL; 

and when I use a function 
void duplicate(QueueNodePtr pHead, QueueNodePtr *pTail)

it will give 
a --> a --> b --> b --> NULL

I can't get around my head with sorting with just reference of tail. 
all I could do is 
a --> b --> a --> b --> NULL

how would you approach this? 
basic code is fine but what I need is hint,
Thanks! 

A: If you can find out the number of elements in the queue (N), then you can simply do the following:
for i = 1 to N
  e = remove(queue)
  insert(queue, e)
  insert(queue, e)

You will get each element duplicated using queue operations.
If you want to manipulate the data directly, then it's no longer a queue - it's a (linked) list.

A: Can't you pop items from the queue and push them, twice, into a new queue?
edit: If you need the original queue to store the results, what's stopping you from popping those items from the temporary queue and pushing back into the original queue.

A: I have a brief pseudo-code below which tries to achieve your objective
void duplicateQueue(QueueNode *head, QueueNode *tail)
{
    QueueNode *curr;
    QueueNode *node;

    //Initialize curr to head
    curr = head
    do
    {
        // Create a new node
        node = (QueueNode *) malloc(sizeof(QueueNode));

        // Initilaize the node
        node->data = curr->data;

        // Create link from node to curr->next
        node->next = curr->next;

        //Create a link from current to new node
        curr->next = node;

        // move current to next original element
        curr = node->next;

    }while(curr != NULL);

}
