Exemplo n.º 1
0
    public int RemoveAll(T element)
    {
        var node = new LinkedListNode <T>(element);

        var range = byOrder.Range(node, true, node, true);

        /*foreach (var item in range)
         * {
         *  byInsertion.Remove(item);
         * }*/

        int howMany = byInsertion.Count(x => x.Equals(element));

        while (howMany > 0)
        {
            byInsertion.Remove(node.Value);
            howMany--;
        }

        var count = byOrder.RemoveAllCopies(node);

        byOrderReversed.RemoveAllCopies(node);

        return(count);
    }
Exemplo n.º 2
0
    public int RemoveAll(T element)
    {
        var node = new LinkedListNode <T>(element);

        foreach (var toRemove in byValue.Range(node, true, node, true))
        {
            byInsertionOrder.Remove(toRemove);
        }

        byValueReversed.RemoveAllCopies(node);
        return(byValue.RemoveAllCopies(node));
    }
Exemplo n.º 3
0
        public int RemoveAll(T element)
        {
            foreach (var item in treeWithDuplicates.Range(element, true, element, true))
            {
                itemsList.Remove(item);
            }

            var count = treeWithDuplicates.RemoveAllCopies(element);

            reversedTreeWithDuplicates.RemoveAllCopies(element);
            return(count);
        }
Exemplo n.º 4
0
 ///<summary>Removes the input node from the open list if it exists</summary>
 ///<param name="node">Node to remove from the open list</param>
 public void Remove(Node node)
 {
     for (int i = 0; i < _openNodes.Count; i++)
     {
         if (node == _openNodes[i])
         {
             _openNodes.RemoveAllCopies(_openNodes[i]);
         }
     }
     #if Debug
     Console.WriteLine("Removed node at " + node.Postition.ToString() + " from the open list");
     #endif
 }
Exemplo n.º 5
0
    public int RemoveAll(T element)
    {
        LinkedListNode <T> node = new LinkedListNode <T>(element);

        foreach (var listNode in acscendingOrder.Range(node, true, node, true))
        {
            insertionOrder.Remove(listNode);
        }

        int deletedElementsCount = acscendingOrder.RemoveAllCopies(node);

        descendingOrder.RemoveAllCopies(element);
        return(deletedElementsCount);
    }
    public int RemoveAll(T element)
    {
        var node  = new LinkedListNode <T>(element);
        var range = byOrder.Range(node, true, node, true);

        foreach (var item in range)
        {
            byInsertion.Remove(item);
        }

        var count = byOrder.RemoveAllCopies(node);

        byOrderReversed.RemoveAllCopies(node);
        return(count);
    }
Exemplo n.º 7
0
    public int RemoveAll(T element)
    {
        LinkedListNode <T> nodeToRemove = new LinkedListNode <T>(element);

        var range = byOrder.Range(nodeToRemove, true, nodeToRemove, true);

        foreach (LinkedListNode <T> node in range)
        {
            byInsert.Remove(node);
        }

        int removedCount = byOrder.RemoveAllCopies(nodeToRemove);

        return(removedCount);
    }
Exemplo n.º 8
0
    public int RemoveAll(T element)
    {
        LinkedListNode <T> node = new LinkedListNode <T>(element);

        foreach (var item in
                 this.byAscending.Range(node, true, node, true))
        {
            this.byInsertion.Remove(item);
        }

        int countRemoved = byAscending.RemoveAllCopies(node);

        byDescending.RemoveAllCopies(node);

        return(countRemoved);
    }
Exemplo n.º 9
0
    public int RemoveAll(T element)
    {
        int firstOccurance  = sortedElements.IndexOf(element);
        int secondoccurance = sortedElements.LastIndexOf(element);

        if (sortedElements.IndexOf(element) < 0)
        {
            return(0);
        }
        else
        {
            //Predicate<T> predicate = x => x.CompareTo(element) == 0;
            this.elements.RemoveAll(x => x.CompareTo(element) == 0);
            sortedElements.RemoveAllCopies(element);
            reversedElements.RemoveAllCopies(element);

            return(secondoccurance - firstOccurance + 1);
        }
    }
    static void Main()
    {
        Console.Write("Bag of Integers: ");
        var bagOfInts = new Bag<int>();
        bagOfInts.Add(3);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(10);
        bagOfInts.Add(20);
        bagOfInts.Add(20);
        bagOfInts.Remove(5);
        bagOfInts.RemoveAllCopies(20);
        bagOfInts.UnionWith(new Bag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(bagOfInts);

        Console.Write("OrderedBag of Integers: ");
        var orderedBagOfInts = new OrderedBag<int>();
        orderedBagOfInts.Add(3);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(10);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Remove(5);
        orderedBagOfInts.RemoveAllCopies(20);
        orderedBagOfInts.UnionWith(new OrderedBag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(orderedBagOfInts);
        Console.WriteLine("Sub-range [5...10]: " +
            orderedBagOfInts.Range(5, true, 10, true));
        
        Console.Write("Set of Integers: ");
        var setOfInts = new Set<int>();
        setOfInts.Add(3);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(10);
        setOfInts.Add(20);
        setOfInts.Add(20);
        setOfInts.Remove(5);
        setOfInts.UnionWith(new Set<int>() { 3, 4, 5 });
        Console.WriteLine(setOfInts);

        Console.Write("OrderedSet of Integers: ");
        var orderedSetOfInts = new OrderedSet<int>();
        orderedSetOfInts.Add(3);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(10);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Remove(5);
        orderedSetOfInts.UnionWith(new OrderedSet<int>() { 3, 4, 5 });
        Console.WriteLine(orderedSetOfInts);
        Console.WriteLine("Sub-range [5...20): " +
            orderedSetOfInts.Range(5, true, 20, false));

        Console.Write("MultiDictionary<string,int>: ");
        var studentGrades = new MultiDictionary<string, int>(true);
        studentGrades.Add("Peter", 3);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Stanka", 5);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Tanya", 6);
        studentGrades.Add("Tanya", 4);
        Console.WriteLine(studentGrades);

        Console.WriteLine("OrderedMultiDictionary<string,int>:");
        var distancesFromSofia = new OrderedMultiDictionary<int, string>(true);
        distancesFromSofia.Add(149, "Plovdiv");
        distancesFromSofia.Add(505, "Varna");
        distancesFromSofia.Add(394, "Bourgas");
        distancesFromSofia.Add(310, "Rousse");
        distancesFromSofia.Add(163, "Pleven");
        distancesFromSofia.Add(163, "Troyan");
        foreach (var distanceTowns in distancesFromSofia)
        {
            Console.WriteLine("\t" + distanceTowns);
        }

        Console.Write("Deque<string>: ");
        var people = new Deque<string>();
        people.AddToBack("Kiro");
        people.AddToBack("Maria");
        people.AddToFront("Steve");
        people.AddManyToBack(new string[] { "Ivan", "Veronika" });
        Console.WriteLine(people);

        Console.Write("BigList<int>: ");
        var ints = new BigList<int>();
        // var ints = new List<int>();
        for (int i = 0; i < 1000000; i++)
        {
            ints.Add(i);
        }
        for (int i = 0; i < 50000; i++)
        {
            ints.Insert(i, i);
        }
        Console.WriteLine(ints.Count);
    }
Exemplo n.º 11
0
    static void Main()
    {
        Console.Write("Bag of Integers: ");
        var bagOfInts = new Bag <int>();

        bagOfInts.Add(3);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(10);
        bagOfInts.Add(20);
        bagOfInts.Add(20);
        bagOfInts.Remove(5);
        bagOfInts.RemoveAllCopies(20);
        bagOfInts.UnionWith(new Bag <int>()
        {
            3, 3, 4, 4, 5, 5
        });
        Console.WriteLine(bagOfInts);

        Console.Write("OrderedBag of Integers: ");
        var orderedBagOfInts = new OrderedBag <int>();

        orderedBagOfInts.Add(3);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(10);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Remove(5);
        orderedBagOfInts.RemoveAllCopies(20);
        orderedBagOfInts.UnionWith(new OrderedBag <int>()
        {
            3, 3, 4, 4, 5, 5
        });
        Console.WriteLine(orderedBagOfInts);
        Console.WriteLine("Sub-range [5...10]: " +
                          orderedBagOfInts.Range(5, true, 10, true));

        Console.Write("Set of Integers: ");
        var setOfInts = new Set <int>();

        setOfInts.Add(3);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(10);
        setOfInts.Add(20);
        setOfInts.Add(20);
        setOfInts.Remove(5);
        setOfInts.UnionWith(new Set <int>()
        {
            3, 4, 5
        });
        Console.WriteLine(setOfInts);

        Console.Write("OrderedSet of Integers: ");
        var orderedSetOfInts = new OrderedSet <int>();

        orderedSetOfInts.Add(3);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(10);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Remove(5);
        orderedSetOfInts.UnionWith(new OrderedSet <int>()
        {
            3, 4, 5
        });
        Console.WriteLine(orderedSetOfInts);
        Console.WriteLine("Sub-range [5...20): " +
                          orderedSetOfInts.Range(5, true, 20, false));

        Console.Write("MultiDictionary<string,int>: ");
        var studentGrades = new MultiDictionary <string, int>(true);

        studentGrades.Add("Peter", 3);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Stanka", 5);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Tanya", 6);
        studentGrades.Add("Tanya", 4);
        Console.WriteLine(studentGrades);

        Console.WriteLine("OrderedMultiDictionary<string,int>:");
        var distancesFromSofia = new OrderedMultiDictionary <int, string>(true);

        distancesFromSofia.Add(149, "Plovdiv");
        distancesFromSofia.Add(505, "Varna");
        distancesFromSofia.Add(394, "Bourgas");
        distancesFromSofia.Add(310, "Rousse");
        distancesFromSofia.Add(163, "Pleven");
        distancesFromSofia.Add(163, "Troyan");
        foreach (var distanceTowns in distancesFromSofia)
        {
            Console.WriteLine("\t" + distanceTowns);
        }

        Console.Write("Deque<string>: ");
        var people = new Deque <string>();

        people.AddToBack("Kiro");
        people.AddToBack("Maria");
        people.AddToFront("Steve");
        people.AddManyToBack(new string[] { "Ivan", "Veronika" });
        Console.WriteLine(people);

        Console.Write("BigList<int>: ");
        var ints = new BigList <int>();

        // var ints = new List<int>();
        for (int i = 0; i < 1000000; i++)
        {
            ints.Add(i);
        }
        for (int i = 0; i < 50000; i++)
        {
            ints.Insert(i, i);
        }
        Console.WriteLine(ints.Count);
    }