0

I've made a class revolved around implementing queues using a linked list. My implementation works fine. However, I have to write a constructor which is passed a queue, and it has to make a duplicate of the original queue. By duplicate, I mean that all the elements in each queue are the same, but the actual nodes are not. How would I go about doing this?

P.S. I may not use anything from the Collections class so that means no clone() method.

dzagnyr
  • 33
  • 6
  • Why not use Collections? – MGorgon Mar 21 '15 at 00:49
  • we aren't allowed to, it is looked at as an attempt to cheat by the instructor. So I must figure out a way to do it otherwise – dzagnyr Mar 21 '15 at 00:50
  • Sorry, but we won't help. It's your homework, so don't cheat your instructor. – MGorgon Mar 21 '15 at 00:52
  • I don't need anybody to literally give me the code. I would just like some advice on what to do. – dzagnyr Mar 21 '15 at 00:53
  • possible duplicate of [How to clone ArrayList and also clone its contents?](http://stackoverflow.com/questions/715650/how-to-clone-arraylist-and-also-clone-its-contents) – MGorgon Mar 21 '15 at 00:56

1 Answers1

1

From what you described the algorithm to achieve this would be:

  1. Write an constructor that accepts your queue as an example
  2. Access the head of the underlying linked list
  3. Traverse the list, using those elements to populate your queue, by creating new nodes to hold the same values
Wusiji
  • 599
  • 1
  • 7
  • 24