예제 #1
0
 public HeapNode GetParent(HeapNode child)
 {
     foreach (HeapNode i in items)
     {
     }
     //HeapNode parent = items.Where(x => x.children.Equals(other.data)).Select(x => x.parent).FirstOrDefault();
     return(null);
 }
예제 #2
0
        public void AddNode(Dictionary <int, int> input)
        {
            foreach (KeyValuePair <int, int> kvp in input)
            {
                //if (items != null)
                //{
                //    items.Add(new HeapNode(kvp.Key));
                //}
                //else
                //{

                //get parent
                //GetParent(kvp.Value);
                HeapNode parent = items.Find(x => x.data == kvp.Value);
                if (parent != null)
                {
                    parent.children.Add(new HeapNode(kvp.Key));
                    //items.Add(parent); // create parent
                }
                else
                {
                    items.Add(new HeapNode(kvp.Key));
                }

                count++;
            }
            //HeapNode root;
            ////get parent
            //root = input.Where(x => x.Value == default(int)).Select(x => new HeapNode(x.Key)).FirstOrDefault();

            //HeapNode pointer = root;
            //while (pointer != null)
            //{
            //    pointer =
            //}
            //foreach (KeyValuePair<int,int> kvp in input)
            //{
            //   heap.children = input.Where(x => x.Value == kvp.Key).Select(x => x.Key).ToArray();
            //   heap.data = kvp.Key;
            //   //heap.parent = kvp.Value;
            //}
        }