In this question you may only use the following functions to access the queue. You should not
Question:
In this question you may only use the following functions to access the queue.
You should not make assumptions about the exact implementation details.
typedef struct { // not known
} queue_t;
// creates a new queue
queue_t* queue_create();
// add a given item to the queue
void enqueue(queue_t* q, i nt item);
// removes an element from the queue // Pre condition: queue is not empty int dequeue(queue_t* q);
// checks if the queue is empty
bool queue_is_empty(queue_t* q);
// frees the queue
void queue_free(queue_t* q);
//--------------------------------------my code---------------------------------------
//Get a pointer to queue, and return a copy with the same elements in the same order
queue_t* copy_queue(queue_t* orig) {
queue_t* copy = queue_create();
queue_t* temp = queue_create();
while(!queue_is_empty(orig)) {
temp = dequeue(orig);
}
int item;
while(!queue_is_empty(temp)) {
item = dequeue(temp);
enqueue(orig, item);
enqueue(copy, item);
}
queue_free(queue_t* q)
return copy;
}
My Question:
Could you check if my code is correct or not?
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill