whu should we use double int pointer in queue
时间: 2024-06-06 13:06:30 浏览: 98
Double int pointer is used in queue to facilitate dynamic memory allocation. When we dynamically allocate memory for a queue, we need to use a double int pointer to create a pointer to a pointer that points to the memory block allocated for the queue. This allows us to create a queue of any size dynamically.
In a queue, we need to keep track of the front and rear elements. When we insert an element into the queue, we need to increment the rear pointer. When we remove an element from the queue, we need to increment the front pointer. Using a double int pointer allows us to modify the front and rear pointers by dereferencing the pointer to the pointer.
Additionally, using a double int pointer allows us to pass the queue to functions by reference. This allows the function to modify the queue directly, rather than creating a copy of the queue. This can be useful when working with large queues, as creating a copy of the queue can be time-consuming and memory-intensive.
阅读全文