The pointer points to the Rear node.
EnQueue: Insert newNode after Rear, and make Rear point to the newly inserted node:
//struct node *newNode;
newNode->next = rear->next;
rear->next = newNode;
rear=newNode;
DeQueue: Delete the Front node, and make the second node the front node.
//rear->next points to the front node.
//front->next points to the second node.
struct node* front;
front = rear->next;
rear->next = front->next;
free(front);
Since there has been a lot of confusion in the comments, let me explain the answer using the pointer `p`
Note that the answer remains unchanged – the below code is just written in a different style.
struct node *p; // a pointer to the rear node
void enqueue(struct node *item) {
item->next = p->next;
p->next = item;
p = item;
}
void dequeue() {
struct node* temp = p->next;
p->next = p->next->next;
free(temp);
}
A single variable $p$ is used to access the Queue
This means that the data-structure only tracks the rear node.
You can create as many temporary pointers as you want – that has nothing to do with the data-structure’s internals.
In enqueue, there’s an extra pointer struct node *item
because if you wish to enqueue something, you need that thing in the first place.
In dequeue, there’s an extra pointer struct node *temp
because if you don’t keep track of the thing that you’re removing in order to free the memory, you will have a memory leak in your code.