Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a list array.
Now i need to go through this array and fill in positions,
depending on the level.
Each level will start at position 10, increasements are 10.
The array is sorted at Level. This may not be changed.
I heared something about recursive loops, but i am not familiar with these.
Below is the start position.

VB
Level|Position|ItemGroup|I
1    |        |PCBFLX   |401246900|
1    |        |CASCER   |402984000|
1    |        |CASCER   |402961200|
1    |        |MPCAH    |401617802|S
2    |        |CASCER   |400094000|
2    |        |CASCER   |402961600|
2    |        |CASCER   |402961000|
2    |        |CASCER   |402965000|
2    |        |CASCER   |402965100|
2    |        |CASCER   |402976900|
2    |        |CASCER   |402965200|
2    |        |DISDIO   |400568400|
1    |        |CASCER   |402961200|
1    |        |CASCER   |402961200|
2    |        |CASCER   |402965200|
3    |        |CASCER   |402965200|
3    |        |CASCER   |402965200|
1    |        |CASCER   |402965200|



Result should be:

Need this to be done ' recursive '?
When level changed numbering should start or to be continued from previous level (same level)

VB
Level|Position|ItemGroup|I
1    |   10   |PCBFLX   |401246900|' Start 10, first item in array lev1
1    |   20   |CASCER   |402984000|' +10
1    |   30   |CASCER   |402961200|' +10
1    |   40   |MPCAH    |401617802|' +10
2    |   10   |CASCER   |400094000|' Start 10, items belong to previous 
2    |   20   |CASCER   |402961600|' +10
2    |   30   |CASCER   |402961000|' +10
2    |   40   |CASCER   |402965000|' +10
2    |   50   |CASCER   |402965100|' +10
2    |   60   |CASCER   |402976900|' +10
2    |   70   |CASCER   |402965200|' +10
2    |   80   |DISDIO   |400568400|' +10
1    |   50   |CASCER   |402961200|' See level 1, pos. 40 '+10
1    |   60   |CASCER   |402961200|' +10
2    |   10   |CASCER   |402965200|' Start 10,items belong to previous 
2    |   20   |CASCER   |402965200|' +10
3    |   10   |CASCER   |402965200|' Start 10, items belong to previous 
3    |   20   |CASCER   |402965200|' +10
1    |   70   |CASCER   |402965200|' See level 1, pos. 60 '+10


Somebody have an idea?
Posted
Updated 27-Sep-10 6:40am
v3
Comments
Sandeep Mewara 26-Sep-10 14:16pm    
What have 'you' tried so far? Posting a problem statment won't help much until you try and post your issue that you face doing it.

A recursive loop is just a function that calls itself. No need to use one here.

One method of performing this is to use a some form of HashMap (a collection) where the level is the key and the last used position is the value for the associated level.

Step through the array, check the hashmap for the level and the last position value, if exists add 10, and update the array and the hashmap, then move on. If it doesn't exists, add it to the hashmap and set the value to 10, and move on.
 
Share this answer
 
Recursion is useful when you have a hierarchy of data.

May be a Tree Traversal or fetching data from parent-child relation. In your case it is very straight forward, so I recommend not to go for recursion, rather use normal loop to do this.

If you want to know about Recursion you can go :
http://www.freenetpages.co.uk/hp/alan.gauld/tutrecur.ht[^]

:rose:
 
Share this answer
 
Comments
borgasia 27-Sep-10 2:17am    
Thanks for your information.
In fact my level is hierarchy.
My product start at level 0.
The product contains several Items. (level 1)
So in fact on level 1 there can be an item wich consists of several other items (level 2) and so on.
When level change increase i have a new start, when decrease, i need to continue the numbering.
I found a normal loop to do so!

<pre lang="cs">private void setPos()
        {
            recBom Bom;
            int position = 0;

            for (int level = 1; level < 10; level++)
            {
                for (int i = 0; i < arrBom.Count; i++)
                {
                    Bom = arrBom[i];
                    if (Bom.Level > level) continue;

                    if (Bom.Level == level)
                    {
                        position += 10;
                        Bom.Position = position.ToString();
                    }
                    else
                    {
                        position = 0;

                    }
                }
            }

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900