Example #1
0
        public bool Delete(int item)
        {
            BSNode temp = root;

            while (true)
            {
                if (temp == null)
                {
                    return(false);
                }
                if (temp.Data == item)
                {
                    Delete(temp);
                    return(true);
                }
                if (item > temp.Data)
                {
                    temp = temp.RightChild;
                }
                else
                {
                    temp = temp.LeftChild;
                }
            }
        }
Example #2
0
        /// <summary>
        /// 查找方法1
        /// </summary>
        /// <param name="item">想要查找对象的数值</param>
        /// <returns></returns>
        public bool Find(int item)
        {
            //return Find(item, root);
            BSNode temp = root;

            while (true)
            {
                if (temp == null)
                {
                    return(false);
                }
                if (temp.Data == item)
                {
                    return(true);
                }
                if (item > temp.Data)
                {
                    temp = temp.RightChild;
                }
                else
                {
                    temp = temp.LeftChild;
                }
            }
        }
Example #3
0
    public void addEdge(float dataParent, float data, float cost, int level, int y)
    {
        BSNode tmp = DSearch(dataParent);

        if (tmp != null && !dataParent.Equals(data))
        {
            if (DSearch(data) == null)
            {
                BSNode nodo = Instantiate(nodoChad).GetComponent <BSNode>();
                nodo.levelx = level;
                nodo.levely = y;
                nodes.Add(nodo);
                GraphGenerator(nodo, y);

                //Comentario para que no se nos olvide
                //Asignarle dato y val
                nodo.data = data;


                tmp.adyacentes.Add(nodo);
                tmp.costoAdyacentes.Add(cost);
            }
            else if (searchPadre(tmp, data) == null)
            {
                tmp.adyacentes.Add(DSearch(data));
                tmp.costoAdyacentes.Add(cost);
            }
        }
    }
Example #4
0
 public Graph(float data, int v)
 {
     if (padre == null)
     {
         padre = new BSNode(data, v);
     }
 }
Example #5
0
    public BSNode searchPadre(BSNode head, float data)
    {
        BSNode tmp = head;

        while (!tmp.Equals(null))
        {
            qv.Enqueue(tmp);
            if (tmp.visitado.Equals(false))
            {
                tmp.visitado = true;
                foreach (BSNode adyacente in tmp.adyacentes)
                {
                    adyacente.visitado = true;
                    qv.Enqueue(adyacente);
                    if (adyacente.getData().Equals(data))
                    {
                        resetVisitados();
                        tmp = adyacente;
                        return(tmp);
                    }
                }
                resetVisitados();
                return(null);
            }
        }
        return(null);
    }
Example #6
0
    public BSNode search(float data)
    {
        Queue <BSNode> qs  = new Queue <BSNode>();
        BSNode         tmp = padre;

        while (!tmp.Equals(null))
        {
            qv.Enqueue(tmp);
            if (tmp.getData().Equals(data))
            {
                resetVisitados();
                return(tmp);
            }
            else if (tmp.visitado != true)
            {
                tmp.visitado = true;
                foreach (BSNode adyacente in tmp.adyacentes)
                {
                    qs.Enqueue(adyacente);
                    qv.Enqueue(adyacente);
                }
            }
            if (qs.Peek().Equals(null))
            {
                resetVisitados();
                return(null);
            }
            tmp = qs.Peek();
            qs.Dequeue();
        }
        return(null);
    }
Example #7
0
    public void InitializeNode(BSNode node, BlueprintSchemeView schemeView)
    {
        Node       = node;
        SchemeView = schemeView;

        // initialize visuals that depends on the type

        if ((node as BSEntry) != null)
        {
            // Initialize as Entry
        }
        else if ((node as BSExit) != null)
        {
            // Initialize as Exit
        }
        else if ((node as BSAction) != null)
        {
            // Initialize as Action
        }
        else if ((node as BSEvaluate) != null)
        {
            // Initialize as Evaluate
        }
        else if ((node as BSBranch) != null)
        {
            // Initialize as Select
        }
    }
 private void MiddleTraversal(BSNode node)
 {
     if (node == null)
     {
         return;
     }
     MiddleTraversal(node.LeftChild);
     builder.Append(node.data + " ");
     MiddleTraversal(node.RightChild);
 }
Example #9
0
 public void GraphGenerator(BSNode nodo, int y)
 {
     if (nodes.Count > 6)
     {
         foreach (BSNode n in nodes)
         {
             n.transform.position = new Vector2(n.levelx, n.levely);
         }
     }
 }
Example #10
0
 /// <summary>
 /// 中序遍历封装方法(先遍历输出左结点,再输出当前结点的数据,再遍历输出右结点)
 /// </summary>
 /// <param name="index">索引(编号-1)</param>
 private void MiddleTravers(BSNode node)
 {
     if (node == null)
     {
         return;
     }
     MiddleTravers(node.LeftChild);
     Console.Write(node.Data + " ");
     MiddleTravers(node.RightChild);
 }
    public void Delete(BSNode node)
    {
        if (node.LeftChild == null && node.RightChild == null)
        {
            if (node.Parent == null)
            {
                root = null;
            }
            else if (node.Parent.LeftChild == node)
            {
                node.Parent.LeftChild = null;
            }
            else if (node.Parent.RightChild == node)
            {
                node.Parent.RightChild = null;
            }
            node.Parent = null;
            return;
        }
        if (node.LeftChild == null && node.RightChild != null)
        {
            node.data       = node.RightChild.data;
            node.RightChild = null;
            node.Parent     = null;
            return;
        }
        if (node.RightChild == null && node.LeftChild != null)
        {
            node.data      = node.LeftChild.data;
            node.LeftChild = null;
            node.Parent    = null;
            return;
        }

        BSNode temp = node.RightChild;

        while (true)
        {
            if (temp.LeftChild != null)
            {
                temp = temp.LeftChild;
            }
            else
            {
                break;
            }
        }
        node.data = temp.data;
        Delete(temp);
    }
Example #12
0
 private void Delete(BSNode node)
 {
     if (node.LeftChild == null && node.RightChild == null)//叶子节点(不包含子节点)
     {
         if (node.Parent == null)
         {
             root = null;
         }
         if (node.Parent.LeftChild == node)
         {
             node.Parent.LeftChild = null;
         }
         else
         {
             node.Parent.RightChild = null;
         }
         return;
     }
     else if (node.LeftChild == null)//有右字节点
     {
         node.Data       = node.RightChild.Data;
         node.RightChild = null;
         return;
     }
     else if (node.RightChild == null)//有左子节点
     {
         node.Data      = node.LeftChild.Data;
         node.LeftChild = null;
         return;
     }
     else//左右都有子节点(从右节点找到最小节点)
     {
         BSNode temp = node.RightChild;
         while (true)//获得最小节点
         {
             if (temp.LeftChild != null)
             {
                 temp = temp.LeftChild;
             }
             else
             {
                 break;
             }
         }
         node.Data = temp.Data;
         Delete(temp);//可能还会有右子节点
     }
 }
Example #13
0
    public BSNode DSearch(float data)
    {
        Stack <BSNode> ss  = new Stack <BSNode>();
        BSNode         tmp = padre;

        ss.Push(tmp);
        if (ss.Count > 0)
        {
            while (tmp != null)
            {
                //cout << tmp->visitado << endl;
                tmp.getData();
                if (tmp.getData().Equals(data))
                {
                    resetVisitados();
                    return(tmp);
                }
                else if (tmp.visitado != true)
                {
                    tmp.visitado = true;
                    qv.Enqueue(tmp);
                    ss.Pop();
                    foreach (BSNode adyacente in tmp.adyacentes)
                    {
                        if (!adyacente.visitado)
                        {
                            ss.Push(adyacente);
                        }
                    }
                }
                else
                {
                    ss.Pop();
                }
                if (ss.Count <= 0)
                {
                    resetVisitados();
                    //cout << "nop" << endl;
                    return(null);
                }
                tmp = ss.Peek();
            }
            resetVisitados();
            return(null);
        }
        return(null);
    }
Example #14
0
        /// <summary>
        /// 添加数据(左子节点小于该节点,右子节点大于该节点)
        /// </summary>
        /// <param name="item">数据值</param>
        public void Add(int item)
        {
            BSNode newNode = new BSNode(item);

            if (root == null)
            {
                root = newNode;
            }
            else
            {
                BSNode temp = root;
                while (true)
                {
                    if (item >= temp.Data)//放在右子节点
                    {
                        if (temp.RightChild == null)
                        {
                            temp.RightChild = newNode;
                            newNode.Parent  = temp;
                            break;
                        }
                        else
                        {
                            temp = temp.RightChild;
                        }
                    }
                    else//放在左子节点
                    {
                        if (temp.LeftChild == null)
                        {
                            temp.LeftChild = newNode;
                            newNode.Parent = temp;
                            break;
                        }
                        else
                        {
                            temp = temp.LeftChild;
                        }
                    }
                }
            }
        }
Example #15
0
 /// <summary>
 /// 查找方法2
 /// </summary>
 /// <param name="item">想要查找对象的数值</param>
 /// <param name="node">开始节点</param>
 /// <returns></returns>
 private bool Find(int item, BSNode node)
 {
     if (node == null)
     {
         return(false);
     }
     if (node.Data == item)
     {
         return(true);
     }
     else
     {
         if (item > node.Data)
         {
             return(Find(item, node.RightChild));
         }
         else
         {
             return(Find(item, node.LeftChild));
         }
     }
 }
    public BSNode searchBFS(float data, BSNode start)
    {
        LinkedList <BSNode> visited = new LinkedList <BSNode>();
        Queue <BSNode>      queue   = new Queue <BSNode>();

        //data = endValue;
        //start = begining;



        visited.AddLast(start);
        queue.Enqueue(start);

        while (queue.Count > 0)
        {
            start = queue.Peek();
            if (start.getData().Equals(data))
            {
                return(start);
            }
            queue.Dequeue();

            for (int i = 0; i < start.adyacentes.Count; i++)
            {
                BSNode tmp = start.adyacentes[i];

                if (!visited.Contains(tmp))
                {
                    visited.AddFirst(tmp);
                    queue.Enqueue(tmp);
                    UgandaKnukles.Add(tmp);
                    Debug.Log("lol " + tmp.data);
                }
            }
        }

        return(null);
    }
Example #17
0
    // Start is called before the first frame update

    public BSNode IterativeBS(BSNode start, BSNode end)
    {
        BSNode current = nodusMaximus;

        stack.Push(nodusMaximus);
        if (!visited.Contains(current))
        {
            visited.Add(current);
        }

        if (current.val == end.data)
        {
            return(current);
        }

        for (int i = current.adyacentes.Count; i >= 0; i--)
        {
            if (!visited.Contains(current.adyacentes[i]))
            {
                stack.Push(current.adyacentes[i]);
            }
        }
        return(null);
    }
    public bool Find1(int item)
    {
        BSNode temp = root;

        while (true)
        {
            if (temp == null)
            {
                return(false);
            }
            if (temp.data == item)
            {
                return(true);
            }
            if (item >= temp.RightChild.data)
            {
                temp = temp.RightChild;
            }
            else
            {
                temp = temp.LeftChild;
            }
        }
    }
Example #19
0
 public void ConnectElements(BSNode left, BSNode right)
 {
     left.AddChild(right);
 }
Example #20
0
 public void AddNodeToCurrentFunction(BSNode node)
 {
 }
Example #21
0
    public void CreateEvaluate()
    {
        BSNode newNode = null;        // = m_blueprint.CreateEvaluate(

        AddNodeToCurrentFunction(newNode);
    }
    // Start is called before the first frame update

    public BSNode IterativeBS(BSNode start, BSNode node)
    {
        if (!node)
        {
            return(null);
        }

        //Aqui se puede añadir a un stack
        List <BSNode>  visited = new List <BSNode>();
        Stack <BSNode> stack   = new Stack <BSNode>();
        BSNode         current = node;

        stack.Push(start);
        while (stack.Count > 0)
        {
            current = stack.Peek();
            stack.Pop();

            if (!visited.Contains(current))
            {
                visited.Add(current);
            }

            if (current.getData() == data)
            {
                //UgandaKnukles.Add(current);
                //Debug.Log(current.data);
                return(current);
            }

            for (int i = current.adyacentes.Count - 1; i >= 0; i--)
            {
                if (!visited.Contains(current.adyacentes[i]))
                {
                    stack.Push(current.adyacentes[i]);
                    UgandaKnukles.Add(current.adyacentes[i]);
                    Debug.Log(current.adyacentes[i].data);
                }
            }
        }
        return(null);
        //BSNode current = nodusMaximus;

        //stack.Push(nodusMaximus);
        //if (!visited.Contains(current))
        //{
        //    visited.Add(current);
        //}

        //if (current.val == end.data)
        //{
        //    return current;
        //}

        //for (int i = current.adyacentes.Count-1; i >= 0; i--)
        //{
        //    if (!visited.Contains(current.adyacentes[i]))
        //    {
        //        stack.Push(current.adyacentes[i]);
        //    }
        //}
        //return null;
    }