Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Operating System questions

Question

j. (1) What is sensitivity analysis?

Answered: 1 week ago

Question

f. What subspecialties and specializations does the person list?

Answered: 1 week ago