I have a List<Node> nodes. And class Node can be defined as follows:
 public class Node
{
    public int Density { get; set; }
    public List<Edge> adjnodes { get; set; }
    public Node()
    {
        adjnodes = new List<Edge>();
    }
    public static int GetDensity(Node n)
    {
        return n.Density;
    }
}
Now, each node in nodes have a density value associated with it which is calculated using following random function:
private static Random rnd = new Random();  
public static int generateRandom(int min, int max)
        {
            int random = rnd.Next(min, max);
            return random;
        }
And I use generateRandom() as follows in the static void main :
for (int i = 0; i < n; i++)
        {
            int densityRandom = YelloWPages.generateRandom(1, 10);
            nodes[i].Density = densityRandom;
            Console.WriteLine("Node is " + nodes[i] + "and density " + nodes[i].Density + "Interest.Array[0] " + nodes[i].P1.InterestArray[0]);
        }
My questions are as follows:
- Suppose there is a List<List<Nodes>> listofnodes. Each List in listofnodes (For example say listofnodes[0] -> which is a first element and a list). has a maximum capacity as defined by user. In our example let it be 10.
I want a forloop to check density of each node in nodes. If it is greater than 5, it should go in one of the lists of listofnodes. Now, suppose there are 100 nodes and 55 of them have density greater than 5. First 10 should go in some listofnodes[i] list while next 10 in listofnodes[i+1]... till all 55 are in one of the lists of listofnodes. But only condition is size of listofnodes[i] or listofnodes[i+1] or whichever should not be more than 10. This is something I tried but it clearly does not work out:
public static void DivideandInsert(List<Node> list)
    {
        List<List<Node>> smallList = new List<List<Node>>();
        for (int i = 0; i < list.Count; i++)
        {
            for (int k = 0; k < smallList.Count; k++)
            {
                if (list[i].Density > 5 && smallList[k].Count != 10)
                {
                    smallList[k].Add(list[i]);
                }
                else smallList[k + 1].Add(list[i]);
            }
        }
    }
If at all it would have worked. But its giving me size of smallList as 0 after the operation is performed.
- If at all this logic is correct, where I am going wrong?
Help to resolve this issue will be highly appreciated.
 
     
     
     
    