예제 #1
0
        static void Main(string[] args)
        {
            /**
             * An array that inclement its length automatically
             **/
            MyArray array = new MyArray(3);

            array.Insert(10);
            array.Insert(11);
            array.Insert(12);
            array.Insert(13);
            array.Insert(14);
            array.Print();
        }
예제 #2
0
        static void Main(string[] args)
        {
            //fastest way to access by index O(1)
            //bad when need to resize O(n), good when we know the size O(1)

            var myArray = new MyArray <int>(1);

            myArray.Insert(10);
            myArray.Insert(20);
            myArray.Insert(30);
            myArray.Insert(40);

            Console.WriteLine(myArray.IndexOf(20));

            myArray.RemoveAt(2);

            myArray.Print();
            Console.ReadLine();
        }
        void IRunner.Run()
        {
            MyArray <int> myArray = new MyArray <int>(16)
            {
                Arr = new int[] { 12, 15, 10, 11, 5, 6, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2 }
            };

            myArray.PrintElementsWhichDoesntHaveAnyHigerOnTheirRight();

            int sum = 15;

            //myArray.PrintElementsHavingSumAs(sum);
            myArray.PrintElementsHavingSumAsUsingDictionary(sum);

            Console.WriteLine("Majority element : " + myArray.FindMajorityElement());

            MyArray <int> myArray2 = new MyArray <int>(9)
            {
                Arr = new int[] { 5, 5, 2, 2, 2, 2, 6, 6, 6 }
            };

            Console.WriteLine("Odd occurance from array where all other are even is:" + myArray2.FindOddOccuranceNumberFromEvenArray());

            myArray2.LeftRotate(3);
            myArray2.Print();

            bool[,] knows = new bool[4, 4] {
                { false, false, false, false },
                { false, false, false, false },
                { false, false, false, false },
                { false, false, false, false }
            };
            ArrayAlgos.PrintCelebrity(knows);

            List <Interval> listOfIntervals = new List <Interval>();

            listOfIntervals.Add(new Interval(6, 8));
            listOfIntervals.Add(new Interval(1, 9));
            listOfIntervals.Add(new Interval(2, 4));
            listOfIntervals.Add(new Interval(4, 7));

            List <Interval> listOfMergedIntervals = ArrayAlgos.GetOverLappingIntervals(listOfIntervals);

            foreach (var item in listOfMergedIntervals)
            {
                Console.WriteLine("(" + item.Start + "," + item.End + ")");
            }

            int[] arr = new int[] { 1, 4, 45, 6, 10, 8 };
            ArrayAlgos.FindTripletsHavingSumAs(arr, 22);

            Console.WriteLine("------------");
            List <int> petrol = new List <int>();

            petrol.Add(6);
            petrol.Add(3);
            petrol.Add(7);
            List <int> distanceToNextStation = new List <int>();

            distanceToNextStation.Add(4);
            distanceToNextStation.Add(6);
            distanceToNextStation.Add(3);
            int starting = ArrayAlgos.CanCompleteCircuit(petrol, distanceToNextStation);

            Console.WriteLine("Start station: {0}", starting);
            Console.ReadLine();
        }