Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to form the following array of array.

Posted on 2013-01-25
7
Medium Priority
?
177 Views
Last Modified: 2013-01-27
Hi there;

sketch1
I try to form the following structure as array. But I am lost in dimensions.
Can someone aid me for C# of the attached image? (Java is also appreciated for learning purpose).

My code is  as follows which is obviously false..

  int[] flower = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[,] []arr = {{ flower, flower}};

Open in new window


This is for educational purpose.

Regards.
0
Comment
Question by:jazzIIIlove
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38818936
Why a multi-dimensional array?...

You're implementing a tree with many elements and an unspecified depth.  I would recommend you actually use an object oriented approach with a List() contained within a Node Class.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38818980
I would suggest a Dictionary of Dictionary of Dictionary...  to mimic a tree.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 38819591
ok Dictionary seems an optimum solution.
So, suppose the depth is 3. What would be the Dictionary initialization for this?

I couldn't visualize this..Can you help me?

Regards.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1336 total points
ID: 38819723
The more I think about it, this could get messy as the number of levels increase. I think I was too focused on your graphic to think smarter at the time  : \

Nevertheless, here is the answer to your recent question:

var tree = new Dictionary<int, Dictionary<int, List<int>>>();

for (int level1 = 1; level1 < 10; level1++)
{
    tree.Add(level1, new Dictionary<int, List<int>>());

    for (int level2 = 1; level2 < 10; level2++)
    {
        tree[level1].Add(level2, new List<int>());
    }
}

tree[1][1].Add(4);

Open in new window


You might want to instead search for a tree implementation that is specific to your scenario. There are many different kinds of trees, so it would be difficult to suggest an implementation without knowing what was to be accomplished.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 38820595
Actually, I am trying to form a some kind of  tree idea in a way that I can do a search.
The image above is for a pattern search.
Set of values will be set in this tree such as:
35671 (numbers inc. level 5),  
3567 (numbers; 3 (level 1), 5(level 2), and 6 (level 3), 7 (level 4)) etc.

Then the input value is searched against the above values,
e.g. 356743
which will fail in 35671 but a success in 3567 since,
3567 in 356743 input matches 3567 in above list whereas,  that input doesn't match 35671 above since 1 kills it.

I think such an algorithm formation above and searching in those per level is a good solution. What do you think?

I thought it would be easier in an array formation that I can search upon*. Btw, your code works as i debug in VS but since you created dictionariy and lists on the fly, I cannot reach the lists directly. Hmm...

Thanks.

Regards.

*since the array of arrays seemed aligned to me and easy to retrieve corresponding value.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1336 total points
ID: 38820808
but since you created dictionariy and lists on the fly, I cannot reach the lists directly.
You can. You just have to index the appropriate levels.

e.g.

List<int> theList = tree[1][1];

...would correspond to:

Screenshot
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 664 total points
ID: 38820876
Gotcha...so you're implementing a sort of DAWG structure but with numbers?
http://www.wutka.com/dawg.html
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question