Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a b* tree data structure using list.

List<list<node>>
List<list<object>>
I am not pretty sure, in the first one I just get 2 levels of the tree, but in the case, the tree will be deeper? I think in the second case fit more with my needs because I can use a list as an object. I read in a forum the usage of a dictionary is better for the tree structure. But I am not sure if I can create a dictionary of a dictionary.

List<<List<<object>> listas;

Dictionary<int, Dictionary<int, Object>> dicionario;

I am new in the data structure topics and collection generics library. Which one is more functionally and easy to use list or dictionaries? by the way, my native language is not English please, don't be rude.
If you have different ideas please feel free to provide them to me

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArbolB
{
    public class pagina
    {
        private int nodo;
        private List<List<int>> elementos;
        private List<List<Object>> listas;
        Dictionary<int, Dictionary<int, Object>> dicionario;
        private List<int> inicial;
        private List<int> final;
        public int Nodo
        {
            get;
            set;
        }
        public List<List<int>> Elementos
        {
            set
            {
                elementos = new List<List<int>>();
            }
            get
            {
                return elementos;
            }
        }

        public pagina()
        {

        }
        public pagina(int numero)
        {
            CrearRaiz(numero);
    
            
        }
        public void AgregarElmento(int numero)
        {
            if(Elementos == null)
            {
                CrearRaiz(numero);
            }
            else
            {
                Elementos[0].Add(numero);
            }
            
        }
        private void CrearRaiz(int numero)
        {
            List<int> raiz = new List<int>();
            raiz.Add(numero);
            Elementos = Elementos;
            Elementos.Add(raiz);
        }
    }
}
Posted
Updated 19-Mar-18 9:00am
v2
Comments
CHill60 19-Mar-18 12:47pm    
"I am not sure if I can create a dictionary of a dictionary" - yes, you can. A dictionary is an object like any other and a dictionary is a collection of objects, so a Dictionary of Dictionaries is possible.
You might find this article interesting: C#/.NET Fundamentals: Choosing the Right Collection Class[^]

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