Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
        static void Main(string[] args)
        {
            MyArray arr1 = new MyArray();

            arr1.push("hi");
            arr1.push("hello");
            arr1.push("heyyyyy");
            arr1.push("Holaaa");



            arr1.remove(1);

            for (int i = 0; i < arr1.length; i++)
            {
                Console.WriteLine("values: " + arr1.get(i));
            }

            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            //1
            Console.Write("Enter N array size: ");
            int N = Int32.Parse(Console.ReadLine());

            MyArray array = new MyArray(N);

            Random rand = new Random();

            for (int i = 0; i < N; i++)
            {
                array[i] = rand.Next(10);
            }

            array.Show();

            Console.WriteLine("Max     - {0:G}", array.Max);
            Console.WriteLine("Min     - {0:G}", array.Min);
            Console.WriteLine("Sum     - {0:G}", array.Sum);
            Console.WriteLine("Average - {0:G}", array.Average);

            array.OddElements.ForEach((element) => { Console.Write("{0} ", element); });

            Console.WriteLine();
            //2

            Console.Write("Enter M matrix size(MxM): ");
            int M = Int32.Parse(Console.ReadLine());

            MyMatrix matrix = new MyMatrix(M, M);

            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    matrix[i, j] = rand.Next(10);
                }
            }

            matrix.Show();

            Console.WriteLine();

            matrix.MatrixOrder();
            //3
            int   count = 5;
            Store store = new Store(count);

            store[0] = new Article("pen", "ATB", 10.2);
            store[1] = new Article("pencil", "Silpo", 12.5);
            store[2] = new Article("book", "Ashan", 20);
            store[3] = new Article("box", "Metro", 50);
            store[4] = new Article("notebook", "Novus", 30.5);

            Console.WriteLine(store[2]);
            Console.WriteLine(store[3]);

            Console.WriteLine(store["pencil"]);
            Console.WriteLine(store["house"]);
            Console.WriteLine(store["table"]);

            Console.WriteLine();
            //4
            Dictionary dictionary = new Dictionary();

            Console.WriteLine(dictionary["книга"]);
            Console.WriteLine(dictionary["дом"]);
            Console.WriteLine(dictionary["ручка"]);
            Console.WriteLine(dictionary["стіл"]);
            Console.WriteLine(dictionary["карандаш"]);
            Console.WriteLine(dictionary["яблуко"]);
            Console.WriteLine(dictionary["солнце"]);
            Console.WriteLine(dictionary["sun"]);
            Console.WriteLine(dictionary["table"]);

            Console.WriteLine(new string('-', 20));

            for (int i = 0; i < 6; i++)
            {
                Console.WriteLine(dictionary[i]);
            }

            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();
        }