public U fold(U u, Queue<T> ts, Function2<T, U, U> function)
    {
        

        // The recursive implementation will overflow the stack for
        // any data set of real size, your job is to implement a
        // non-recursive solution
    	
        // return fold(function.apply(ts.poll(), u), ts, function);
        
        while(true) {
        	if(u == null || ts == null || function == null)
                throw new IllegalArgumentException();

            if (ts.isEmpty()) {
                return u;
            }
            
            u = function.apply(ts.poll(), u);
            
        }
        
        
        //return null;
    }