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
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?
Step by Step Solution
3.42 Rating (142 Votes )
There are 3 Steps involved in it
Step: 1
Your code has a few issues 1 In the line temp dequeueorig youre assigning the result of dequeueorig ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started