Skip to content
Advertisement

Tag: algorithm

detect last foreach loop iteration

Supposing that I have some foreach loop like this: Is there a way to check inside foreach that the actual name is the last one in Set without a counter? I didn’t found here some question like this. Answer There isn’t, take a look at How does the Java ‘for each’ loop work? You must change your loop to use

Heapsort Within a Given Range

I am trying to write a Heapsort method that only performs the sort within a given range passed into the method. The ranges low and high are passed in and these values correspond to values inside the heap, not indices of the heap. For example, the input array might be: 28 10 49 20 59 61 17 and if low

Connect 4 check for a win algorithm

I know there is a lot of of questions regarding connect 4 check for a win. The issue is that most of other algorithms make my program have runtime errors, because they try to access an index outside of my array. My algorithm is like this: count is the variable that checks for a win if count is equal or

How to get Cartesian product from multiple lists?

Say I have several List<T>s, I will put them into another list or other collections, so I don’t know how many list<T> I have until I call List<List<T>>.size() Take below List<Integer> as an example: How can I get the result of list1*list2*list3*…listn as a Cartesian product? For example: should be: Answer You can use recursion to achieve it, your base

Advertisement