예제 #1
0
    public DSNode lookForDPS(float data, DSNode node)
    {
        if (node.Equals(null))
        {
            return(null);
        }

        if (node.value.Equals(data))
        {
            last = node;
            return(node);
        }

        //Aqui se puede añadir a un stack

        for (int i = 0; i < node.vertex.Count; i++)
        {
            if (!node.vertex[i].Equals(null))
            {
                lookForDPS(data, node.vertex[i]);
            }
            if (last.value.Equals(data))
            {
                return(last);
            }
        }

        //Aqui se borraría del stack
        return(null);
    }
예제 #2
0
    void erase(float data)
    {
        DSNode to_erase = searchDFS(data);

        if (!to_erase.Equals(null))
        {
            //Aqui puede haver un problema
            to_erase = null;
        }
    }
예제 #3
0
    DSNode lookforDPSIterative(float data, DSNode node)
    {
        if (node.Equals(null))
        {
            return(null);
        }

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

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

            if (!visited.Contains(current))
            {
                //std::cout << current->value << " ";
                Debug.Log(current.value);
                visited.AddLast(current);
            }

            if (current.value.Equals(data))
            {
                return(current);
            }

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

        return(null);
    }