At beginning of this task you are given a two dimensional array which visualize a map. Each element of this array will take one of the following values: 0 (which represents water), 1 (which represents land).
These values will form islands on water.
For example:
0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
1 1 1 0 0 0 1 0 0
1 1 0 0 0 1 1 1 0
0 0 0 0 0 1 1 0 0
0 0 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0
(This example illustrates 4 islands. Counting from left upper corner: First Island is made of six land elements, Second Island is also made of six land elements. Third island consists of 3 elements, and last one is made of two elements).
Write a short program, which will count the number of islands. Following data structure could be varying in size. Take into assumption, that data structure given to you could be very large in size, so beware of implementation that could result in stack overflow or out of memory exception.