public static void Init()
        {
            Node1 a = new Node1(null, "A");
            Node1 b = new Node1(a, "B");
            Node1 c = new Node1(a, "C");

            a.left  = b;
            a.right = c;

            Node1 d = new Node1(b, "D");
            Node1 e = new Node1(b, "E");

            b.left  = d;
            b.right = e;

            Node1 h = new Node1(c, "H");

            c.right = h;

            Node1 g = new Node1(d, "G");
            Node1 f = new Node1(d, "F");

            d.right = f;
            d.left  = g;

            Console.WriteLine(deep(d, f).x);
            Console.WriteLine(deep(c, g).x);
            Console.WriteLine(deep(e, b).x);
            Console.WriteLine(deep(e, f).x);
        }
Esempio n. 2
0
            public T GetPreviousElement(int index)
            {
                if (this == null)
                {
                    return(null);
                }
                if (index - 1 >= 0)
                {
                    return(this.data[index - 1]);
                }

                Node  sf = this;
                Node1 n1 = this.parent;

                for (; n1 != null; sf = n1, n1 = n1.parent)
                {
                    if (sf.index - 1 >= 0)
                    {
                        Node n2 = n1.data[sf.index - 1];
                        return(n2[n2.weight - 1]);
                    }
                }

                return(null);
            }
Esempio n. 3
0
            }   // end of Edge NearestNode

            public void Rotate(Matrix delta)
            {
                Node0.Rotate(delta);
                Node1.Rotate(delta);

                Path.RecalcHeights();
            }
Esempio n. 4
0
        void HandleSelfStabilization()
        {
            if (Program.Presenter.cb_selfStab.Checked)
            {
                //Node1.UserDefined_SingleInitiatorProcedure(Node1);
                //Node2.UserDefined_SingleInitiatorProcedure(Node2);

                Task.Run(() =>
                {
                    Node1.Underlying_Send(new AsyncSimulator.Message
                    {
                        Source        = Node1,
                        DestinationId = Node2.Id
                    });
                });

                //Task.Run(() =>
                //{
                //    Node2.Underlying_Send(new AsyncSimulator.Message
                //    {
                //        Source = Node2,
                //        Destination = Node1
                //    });
                //});
            }
        }
Esempio n. 5
0
 public Node(int level)
 {
     this.level  = level;
     this.list   = null;
     this.parent = null;
     this.weight = 0;
 }
 public override int GetHashCode()
 {
     unchecked
     {
         return(Node1.GetHashCode() ^ Node2.GetHashCode() ^ Node3.GetHashCode() ^ Node4.GetHashCode());
     }
 }
        //delete the element from the linked list if the data is given
        public void DeleteLL(int data)
        {
            // Store head node
            Node1 temp = head, prev = null;

            // If head node itself holds the key to be deleted
            if (temp != null && temp.data == data)
            {
                head = temp.next; // Changed head
                return;
            }

            // Search for the key to be deleted, keep track of the
            // previous node as we need to change temp.next
            while (temp != null && temp.data != data)
            {
                prev = temp;
                temp = temp.next;
            }

            // If key was not present in linked list
            if (temp == null)
            {
                return;
            }

            // Unlink the node from linked list
            prev.next = temp.next;
        }
        public static Node1 deep(Node1 a1, Node1 a2)
        {
            LinkedList <Node1> first = new LinkedList <Node1>();

            while (a1 != null)
            {
                if (first.Count == 0)
                {
                    first.AddFirst(a1);
                }
                else
                {
                    first.AddAfter(first.Last, a1);
                }
                a1 = a1.parent;
            }

            LinkedList <Node1> second = new LinkedList <Node1>();

            while (a2 != null)
            {
                if (second.Count == 0)
                {
                    second.AddFirst(a2);
                }
                else
                {
                    second.AddAfter(second.Last, a2);
                }
                a2 = a2.parent;
            }

            int   c1     = first.Count;
            int   c2     = second.Count;
            Node1 common = null;

            while (c1 > 0 && c2 > 0)
            {
                if (first.ElementAt(c1 - 1).x != second.ElementAt(c2 - 1).x)
                {
                    common = first.ElementAt(c1);
                    break;
                }
                c2--;
                c1--;
            }

            if (common == null)
            {
                if (c1 == 0)
                {
                    return(second.ElementAt(1));
                }
                if (c2 == 0)
                {
                    return(first.ElementAt(1));
                }
            }
            return(common);
        }
Esempio n. 9
0
 public override string ToString()
 {
     return("[ " + Node1.ToString() + "\t" +
            Node2.ToString() + "\t" +
            Node3.ToString() + "\t" +
            Node4.ToString() + " ]");
 }
Esempio n. 10
0
        /* As banner rotating through flash so that we need add this information to the .XML file */
        public void AddBannerToXml(string tempPath, string ImageName2, string ImageCoupon)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(Session["HomePath"].ToString() + "banners_Cat.xml");
            //Create a new node
            XmlNodeList Node;

            Node = xmldoc.GetElementsByTagName("bannerName");
            XmlElement banners   = xmldoc.CreateElement("banners");
            XmlElement banner    = xmldoc.CreateElement("banner");
            XmlElement name      = xmldoc.CreateElement("name");
            XmlElement body      = xmldoc.CreateElement("body");
            XmlElement imagePath = xmldoc.CreateElement("imagePath");
            XmlElement link      = xmldoc.CreateElement("link");

            name.InnerText      = "New";
            body.InnerText      = "Lorem Ipsum";
            imagePath.InnerText = "../StoreData/Baner/" + ddlPage.SelectedItem.Text + "/" + ImageName2;
            link.InnerText      = Session["HomePath"] + "PrintCoupon.aspx?CouponID=" + ImageCoupon + "&PageName=" + ddlPage.SelectedItem.Text;
            banner.AppendChild(name);
            banner.AppendChild(body);
            banner.AppendChild(imagePath);
            banner.AppendChild(link);
            XmlNodeList Node1;

            Node1 = xmldoc.GetElementsByTagName("banners");
            Node1.Item(Convert.ToInt32(ddlUserType.SelectedValue)).AppendChild(banner);   // Important Count
            XmlNodeList Node2;

            Node2 = xmldoc.GetElementsByTagName("bannerName");
            Node2.Item(Convert.ToInt32(ddlUserType.SelectedValue)).FirstChild.InnerText = Node1.Item(Convert.ToInt32(ddlUserType.SelectedValue)).ChildNodes.Count.ToString();
            xmldoc.Save(ContentManager.GetPhysicalPath(Session["HomePath"].ToString() + "banners_Cat.xml"));
        }
Esempio n. 11
0
        //add in first
        public void AddFirst(int data)
        {
            Node1 NewNode = new Node1(data);

            NewNode.next = head;
            head         = NewNode;
        }
Esempio n. 12
0
        public int Search1(string key)
        {
            int   level;
            int   length = key.Length;
            int   i;
            Node1 pCrawl = root;

            for (level = 0; level < length; level++)
            {
                i = key[level] - 'a';

                if (pCrawl.children[i] == null)
                {
                    return(0);   //Absent
                }
                pCrawl = pCrawl.children[i];
            }
            if (pCrawl != null)
            {
                if (pCrawl.isEndOfWord == true)
                {
                    return(1);
                }
                return(0);
            }
            else
            {
                return(0);       //Absent
            }
        }
Esempio n. 13
0
        public int Delete1(string key)
        {
            int   length = key.Length;
            int   i;
            Node1 pCrawl = root;


            // iterating from the first letter to the last letter
            for (int level = 0; level < length; level++)
            {
                i = key[level] - 'a';
                if (i < 0)
                {
                    break;
                }


                if (pCrawl.children[i] == null)
                {
                    pCrawl.children[i] = getNode1();
                }

                pCrawl = pCrawl.children[i];
            }

            if (pCrawl.isEndOfWord != true)
            {
                return(0);
            }
            else
            {
                pCrawl.isEndOfWord = false; return(1);
            };
        }
Esempio n. 14
0
        public void Insert1(string key)
        {
            int   length = key.Length;
            int   i;
            Node1 pCrawl = root;


            // iterating from the first letter to the last letter
            for (int level = 0; level < length; level++)
            {
                i = key[level] - 'a';
                if (i < 0)
                {
                    break;
                }


                if (pCrawl.children[i] == null)
                {
                    pCrawl.children[i] = getNode1();
                }

                pCrawl = pCrawl.children[i];
            }
            pCrawl.isEndOfWord = true;
        }
Esempio n. 15
0
 public void Insert(T data)
 {
     // TODO balance the tree after x number of entries
     if (data.CompareTo(Data) <= 0)
     {
         if (Node1 != null)
         {
             Node1.Insert(data);
         }
         else
         {
             Node1 = new BiNode <T>(data);
         }
     }
     else
     {
         if (Node2 != null)
         {
             Node2.Insert(data);
         }
         else
         {
             Node2 = new BiNode <T>(data);
         }
     }
 }
Esempio n. 16
0
 /// <summary>
 /// 内部状態の整合性をチェックします。
 /// 内部状態に異常がある場合には例外を投げます。
 /// </summary>
 public void DbgCheckState()
 {
     if (this.root.level > 0)
     {
         Node1 node = (Node1)this.root;
         node.DbgCheckState();
     }
 }
Esempio n. 17
0
 public void ClearEdit()
 {
     Moving = false;
     Edit   = false;
     Select = false;
     Node0.ClearEdit();
     Node1.ClearEdit();
     Path.ClearEdit();
 }
Esempio n. 18
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Node1.GetHashCode();
         hashCode = (hashCode * 397) ^ Node2.GetHashCode();
         return(hashCode);
     }
 }
Esempio n. 19
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = 1001471489;
         hashCode = hashCode * -1521134295 + Node1.GetHashCode();
         hashCode = hashCode * -1521134295 + Node2.GetHashCode();
         return(hashCode);
     }
 }
Esempio n. 20
0
            public int GenericMethod <valueType>(valueType value)
            {
                Node1 node = value as Node1;

                if (node == null)
                {
                    return(Value - (value as Node2).Value);
                }
                return(Value + node.Value);
            }
Esempio n. 21
0
        internal static int GenericStaticMethod <valueType>(valueType value)
        {
            Node1 node = value as Node1;

            if (node == null)
            {
                return((value as Node2).Value - 1);
            }
            return(node.Value + 1);
        }
Esempio n. 22
0
        public void DisplayStack()
        {
            Node1 temp = head;

            while (temp != null)
            {
                Console.WriteLine(temp.data);
                temp = temp.next;
            }
        }
Esempio n. 23
0
 public static void InOrderTraversal(Node1 root, int i = 0)
 {
     if (root == null)
     {
         return;
     }
     // result = new int[1];
     InOrderTraversal(root.leftNode);
     Console.Write(root.data + " ");
     InOrderTraversal(root.rightNode);
 }
Esempio n. 24
0
        /* As banner rotating through flash so that we need add this information to the .XML file */
        public void AddBannerToXml(string tempPath, string ImgCoupon)
        {
            string Path = string.Empty;

            if (ViewState["PetType"].ToString() == "1")
            {
                Path = Session["HomePath"] + "banners.xml";
            }
            if (ViewState["PetType"].ToString() == "2")
            {
                Path = Session["HomePath"] + "banners_Dog.xml";
            }
            if (ViewState["PetType"].ToString() == "3")
            {
                Path = Session["HomePath"] + "banners_Cat_Dog.xml";
            }

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(Path);
            //Create a new node
            XmlNodeList Node;

            Node = xmldoc.GetElementsByTagName("numberOfBanners");
            XmlNodeList Node_Count;

            Node_Count = xmldoc.GetElementsByTagName("banner");
            for (int i = 0; i < Node.Count; i++)
            {
                XmlElement id = (XmlElement)xmldoc.GetElementsByTagName("numberOfBanners")[i];
                id.InnerText = (Node_Count.Count + 1).ToString();
            }
            XmlElement banners   = xmldoc.CreateElement("banners");
            XmlElement banner    = xmldoc.CreateElement("banner");
            XmlElement name      = xmldoc.CreateElement("name");
            XmlElement body      = xmldoc.CreateElement("body");
            XmlElement imagePath = xmldoc.CreateElement("imagePath");
            XmlElement link      = xmldoc.CreateElement("link");

            name.InnerText      = "OnE";
            body.InnerText      = "Lorem Ipsum";
            imagePath.InnerText = "../" + tempPath;
            link.InnerText      = Session["HomePath"] + "PrintCoupon.aspx?CouponID=" + ImgCoupon;
            banner.AppendChild(name);
            banner.AppendChild(body);
            banner.AppendChild(imagePath);
            banner.AppendChild(link);
            XmlNodeList Node1;

            Node1 = xmldoc.GetElementsByTagName("banners");
            Node1.Item(0).AppendChild(banner);

            xmldoc.Save(ContentManager.GetPhysicalPath(Path));
        }
Esempio n. 25
0
        protected override void HandleVisualization()
        {
            _Draw(SolidPen);

            Path = new GraphicsPath();
            Path.AddLine(Node1.Visualizer.Location, Node2.Visualizer.Location);

            /// redraw the nodes
            Node1.Visualizer.Draw(Node1.GetState());
            Node2.Visualizer.Draw(Node2.GetState());
        }
Esempio n. 26
0
        //display the linked list or print
        public void Display1()
        {
            Console.WriteLine("Linklist elements are");
            Node1 temp = head;

            while (temp != null)
            {
                Console.Write(temp.data + " ");
                temp = temp.next;
            }
        }
Esempio n. 27
0
        private void PushLevel(Node node2)
        {
            __dbg__.AssertBList(root.level == node2.level);

            Node1 newroot = new Node1(root.level + 1);

            newroot.InsertNode(0, root);
            newroot.InsertNode(1, node2);
            newroot.set_list(this);
            this.root = newroot;
        }
Esempio n. 28
0
            static IEnumerable <Node1> FindNodesContaining(Node1 node)
            {
                foreach (var parent in node.Parents)
                {
                    yield return(parent);

                    foreach (var grandparent in FindNodesContaining(parent))
                    {
                        yield return(grandparent);
                    }
                }
            }
Esempio n. 29
0
        public void TwoNodesOfTheSameTypeWithTheSameIdShouldBeEqual()
        {
            // arrange
            var node1 = new Node1("node1");
            var node2 = new Node1("node1");

            // act
            var equal = EqualityComparer<Node>.Default.Equals(node1, node2);

            // Assert
            Assert.That(equal, Is.True, "Nodes are not equal");
        }
Esempio n. 30
0
        public void DisplayQueue()
        {
            Node1 temp  = head;
            int   count = 0;

            Console.WriteLine("Display the queue");
            while (temp != null)
            {
                count++;
                Console.WriteLine("position " + count + " in queue : " + temp.data);
                temp = temp.next;
            }
        }
Esempio n. 31
0
        private void PopLevel()
        {
            __dbg__.AssertBList(this.root.level > 0);
            Node1 r = (Node1)this.root;

            __dbg__.AssertBList(r.data.Count <= 1);

            Node newroot = r.data[0];

            // newroot.list=; // ok
            newroot.parent = null;
            this.root      = newroot;
        }