Ejemplo n.º 1
0
        public static ListB <T> operator +(ListB <T> l1, ListB <T> l2)
        {
            ListB <T> combinedList = new ListB <T>();

            for (int i = 0; i < l1.Count; i++)
            {
                combinedList.Add(l1[i]);
            }

            for (int i = 0; i < l2.Count; i++)
            {
                combinedList.Add(l2[i]);
            }

            return(combinedList);
        }
Ejemplo n.º 2
0
        public static ListB <T> operator -(ListB <T> l1, ListB <T> l2)
        {
            ListB <T> newList = new ListB <T>();

            for (int i = 0; i < l1.Count; i++)
            {
                newList.Add(l1[i]);
            }


            for (int i = 0; i < newList.Count; i++)
            {
                for (int j = 0; j < l2.Count; j++)
                {
                    if (newList[i].Equals(l2[j]))
                    {
                        newList.Remove(l2[j]);
                    }
                }
            }

            return(newList);
        }
Ejemplo n.º 3
0
        public ListB <T> Zip(ListB <T> list)
        {
            ListB <T> temp1 = new ListB <T>();
            ListB <T> temp2 = new ListB <T>();

            for (int i = 0; i < list.Count; i++)
            {
                temp1.Add(list[i]);
            }
            for (int i = 0; i < listArray.Length; i++)
            {
                temp2.Add(listArray[i]);
            }
            ListB <T> zippedList = new ListB <T>();
            int       maxCount;

            if (temp1.Count > temp2.Count)
            {
                maxCount = temp1.Count;
            }
            else
            {
                maxCount = temp2.Count;
            }
            for (int i = 0; i < maxCount; i++)
            {
                if (i < temp2.Count)
                {
                    zippedList.Add(temp2[i]);
                }
                if (i < temp1.Count)
                {
                    zippedList.Add(temp1[i]);
                }
            }
            return(zippedList);
        }
Ejemplo n.º 4
0
    {   /// <summary>
        // DO NOT DELETE BELOW CODE IT IS DEMONSTARTING SORTING WITH INTEGERS AND STRINGS USING IComparer!!!!
        /// </summary>
        // Main Method
        public static void Main()
        {
            List <int> list1 = new List <int>
            {
                // list elements
                1, 5, 6, 2, 4, 3
            };

            Console.WriteLine("Original List");

            foreach (int g in list1)
            {
                // Display Original List
                Console.WriteLine(g);
            }

            foreach (int g in list1)
            {
                // Display sorted list
                Console.WriteLine(g);
            }

            ListB <IComparer> gg = new ListB <IComparer>();


            Console.WriteLine("\nSort with a comparer:");

            // use of List<T>.Sort(IComparer<T>)
            // method. The comparer is "gg"
            list1.Sort(gg);

            foreach (int g in list1)
            {
                // Display sorted list
                Console.WriteLine(g);
            }
            { }
            List <string> list2 = new List <string>();

            // list elements
            list2.Add("A");
            list2.Add("I");
            list2.Add("G");
            list2.Add("B");
            list2.Add("E");
            list2.Add("H");
            list2.Add("F");
            list2.Add("C");
            list2.Add("J");
            list2.Add("D");

            Console.WriteLine("Original List");

            // Display Original List
            foreach (string h in list2)
            {
                // Display Original List
                Console.WriteLine(h);
            }

            // "ggg" is the object
            ListB <IComparer> ggg = new ListB <IComparer>();

            Console.WriteLine("\nSort with a comparer:");

            // sort the list with a
            // specified comparer "ggg"
            list2.Sort(ggg);

            // Display sorted List
            foreach (string h in list2)
            {
                // Display sorted list
                Console.WriteLine(h);
            }

            ///Below here is where you can play DO NOT delete above code !!!!
        }