View Single Post
  #2 (permalink)  
Old 01-29-2008, 01:36 AM
jelly's Avatar
jelly jelly is offline
Member
 
Join Date: Jan 2008
Location: Somerset, UK
Posts: 46
jelly is on a distinguished road
I suspect that the reason your code is crashing is due to the code

Code:
if (q1 == null){ q1.add(data); }
you test the q1 reference to be null, and having found it is, you then try to use it. I suspect there are two things you need to change, firstly you need to instantiate the Queues,currently you create reference variables ( q1 and q2 ) that are capable of referring to a Queue but you never actually create the Queues. Maybe something like

Code:
Queue<Integer> q1 = new LinkedList<Integer>(); Queue<Integer> q2= new LinkedList<Integer>();
also you are getting confused between

Code:
q1 == null
which says that the variable is not currently referencing a Queue and

Code:
q1.peek() == null
which implies the Queue is empty - though there are edge cases where this may not be true, just don't go there yet
__________________
-- Hope that helps

Last edited by jelly : 01-29-2008 at 01:39 AM.
Reply With Quote