Kindly solve the following exercise in Java
Question I.2 (8 pts)
We want to implement two iterators on the LinkedMeshgrid class:
1. A first iterator on positions.
2. A second iterator on the elements (which should rely on the position iterator).
In your implementation, you might want to consider the following points:
- It is up to you to decide how you want to skim through the nodes (you can, for example, start from node no. 6 then scan the whole first row, then scan the second row, starting from node no. 5 - but any alternative path which goes through all the nodes is perfectly valid).
- Keep in mind that when you have returned all the nodes, the method hasNext from the iterator should return null.
An instance of the Meshgrid.java class always contains h * w nodes, where h (height) and w (width) are defined as instance variables (equivalent of the size parameter). Hence, it might be a good idea to define the first node of the instance as the top-left node and the last one as the bottom-right node. Also, note that to make your life easier, you can just consider square (w = h) lists.
Node no. 6 n1,6 n2,6 n3,6 n4,6 n5,6 n6,6
Node no. 5 n1,5 n2,5 n3,5 n4,5 n5,5 n6,5
Figure 1: An instance of the class Meshgrid.java