Exemplo n.º 1
0
        static void RunProgram(ref bool programRunning)
        {
            // define two linked list objects
            LinkedList <int> list1 = new LinkedList <int>();
            LinkedList <int> list2 = new LinkedList <int>();

            int failIndex   = 0;
            int list1Length = InputHandling.ReadCollectionLength("List 1 length: ");

            InputHandling.ReadCollectionElements(ref list1, list1Length, ref failIndex);

            failIndex = 0;
            int list2Length = InputHandling.ReadCollectionLength("List 2 length: ");

            InputHandling.ReadCollectionElements(ref list2, list2Length, ref failIndex);

            Sorting.BubbleSort(ref list1);
            Sorting.BubbleSort(ref list2);
            LinkedList <int> mergedList = Merge.MergeLinkedList(list1, list2);

            OutputHandling.Message("First List: ", ConsoleColor.Yellow, false);
            OutputHandling.PrintLinkedList(list1);
            OutputHandling.Message("Second List: ", ConsoleColor.Yellow, false);
            OutputHandling.PrintLinkedList(list2);
            OutputHandling.Message("Merged Lists: ", ConsoleColor.Yellow, false);
            OutputHandling.PrintLinkedList(mergedList);

            OutputHandling.Question("Do you want to merge other two Linked Lists? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 2
0
        static void RunProgram(ref bool programRunning)
        {
            int linkedListLength = InputHandling.ReadCollectionLength("Length of Linked List: ");
            SingleLinkedList singleLinkedList = new SingleLinkedList();
            int failIndex = 0;

            InputHandling.ReadCollectionElements(ref singleLinkedList, linkedListLength, ref failIndex);
            ReverseLinkedList.PerformReversal(ref singleLinkedList, ref linkedListLength);
            OutputHandling.Question("Do you want to reverse another Linked List? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 3
0
        static void RunProgram(ref bool programRunning)
        {
            int arrLength = InputHandling.ReadCollectionLength();

            int[] array = new int[arrLength];
            int   index = 0;

            InputHandling.ReadCollectionElements(ref array, arrLength, ref index);
            Console.WriteLine("The sum of the even array elements is: {0}", CalculateSum.Sum(array, arrLength));
            OutputHandling.Question("Do you want to print the sum of other even numbers in an array? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 4
0
        static void RunProgram(ref bool programRunning)
        {
            int linkedListLength        = InputHandling.ReadValue("Sorted Linked List Length: ");
            LinkedList <int> linkedList = new LinkedList <int>();
            int index = 0;

            InputHandling.ReadCollectionElements(ref linkedList, linkedListLength, ref index);
            LinkedListDuplicates.RemoveLinkedListDuplicates(ref linkedList);
            LinkedListDuplicates.DisplayLinkedList(linkedList);
            OutputHandling.Question("Do you want to remove duplicates from another sorted Linked List? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 5
0
        static void RunProgram(ref bool programRunning)
        {
            int myListLength        = InputHandling.ReadCollectionLength("Singly Linked List Length: ");
            SingleLinkedList myList = new SingleLinkedList();
            int failIndex           = 0;

            InputHandling.ReadCollectionElements(ref myList, myListLength, ref failIndex);
            int thirdFromEnd = ThirdFromEnd.FindThirdFromEnd(myList);

            OutputHandling.Message("The third element counting from the end is: " + thirdFromEnd, ConsoleColor.Green);
            OutputHandling.Question("Do you want to find another third last element of a linked list? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 6
0
        static void RunProgram(ref bool programRunning)
        {
            int arrLength = InputHandling.ReadCollectionLength();
            int sum       = InputHandling.ReadValue("Input sum: ");

            int[] array = new int[arrLength];
            int   index = 0;

            InputHandling.ReadCollectionElements(ref array, arrLength, ref index);
            PairsEqualToSum.PrintElements(array, arrLength, sum);
            OutputHandling.Question("Do you want to check other array if the sum of elements is equal to given elements in an array? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 7
0
        static void RunProgram(ref bool programRunning)
        {
            int arrLen = InputHandling.ReadCollectionLength();

            int[] arr           = new int[arrLen];
            int   lastFailIndex = 0;

            InputHandling.ReadCollectionElements(ref arr, arrLen, ref lastFailIndex);
            int pivot = InputHandling.ReadCollectionIndex(arrLen, "Set pivot point: ");

            int[] arrRotated = ArrayManipulation.RotateArray(arr, arrLen, pivot);
            OutputHandling.PrintArray(arrRotated, arrRotated.Length, "Rotated array: ");
            OutputHandling.Question("Do you want to rotate another array? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 8
0
        static void RunProgram(ref bool programRunning)
        {
            int arrLen = InputHandling.ReadCollectionLength();

            int[] arr   = new int[arrLen];
            int   index = 0;

            InputHandling.ReadCollectionElements(ref arr, arrLen, ref index);
            int[] freqArray = FrequencyOfElements.GenerateFrequencyArray(arr, arrLen);
            int   maxIndex  = MaxMinArray.MaxIndex(freqArray, freqArray.Length);

            OutputHandling.Message("The element with the most occurences inside the array is " + maxIndex, ConsoleColor.Magenta);
            OutputHandling.Question("Do you want to find another value in an array with the most numbers of occurences? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 9
0
        static void RunProgram(ref bool programRunning)
        {
            OutputHandling.Message("This program accepts an array and sorts it using Bubble Sort");

            int arrLen = InputHandling.ReadCollectionLength();

            int[] arr           = new int[arrLen];
            int   lastFailIndex = 0;

            InputHandling.ReadCollectionElements(ref arr, arrLen, ref lastFailIndex);
            Sorting.BubbleSort(ref arr, arrLen);
            OutputHandling.PrintArray(arr, arrLen, "Sorted array using Bubble sort: ");
            OutputHandling.Question("Do you want to sort another array with Bubble sort? Y / N");

            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 10
0
        static void RunProgram(ref bool programRunning)
        {
            int arrLen = InputHandling.ReadCollectionLength();

            int[] arr   = new int[arrLen];
            int   index = 0;

            InputHandling.ReadCollectionElements(ref arr, arrLen, ref index);
            bool hasDuplicates = DuplicatesInArray.HasDuplicates(arr, arrLen);

            if (hasDuplicates)
            {
                OutputHandling.Message("The array contains duplicates", ConsoleColor.Magenta);
            }

            else
            {
                OutputHandling.Message("The array does not contain duplicates", ConsoleColor.Cyan);
            }

            OutputHandling.Question("Do you want to check another array for duplicates? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Exemplo n.º 11
0
        static void RunProgram(ref bool programRunning)
        {
            int listLength          = InputHandling.ReadCollectionLength("Length of linked list: ");
            SingleLinkedList myList = new SingleLinkedList();

            int lastFailIndex = 0;

            InputHandling.ReadCollectionElements(ref myList, listLength, ref lastFailIndex);

            // create cycle
            OutputHandling.Question("Do you want to add a cycle to the linked list?  Y / N");
            bool AddCycles = InputHandling.QuestionOptions(false);

            if (AddCycles)
            {
                int bindPoint = InputHandling.ReadCollectionIndex(listLength, "Point to form a cycle to: ");
                Cycle.CreateCycle(ref myList, ref listLength, bindPoint);
            }

            // cycle exists?

            bool hasCycles = DetectCycles.CycleExists(myList);

            if (hasCycles)
            {
                OutputHandling.Message("The Single Linked List has a cycle", ConsoleColor.Green);
            }

            else
            {
                OutputHandling.Message("The Single Linked List does not contain cycles", ConsoleColor.DarkMagenta);
            }

            OutputHandling.PrintSingleLinkedList(myList, listLength);
            OutputHandling.Question("Do you want to detect cycles in another linked list?");
            programRunning = InputHandling.QuestionOptions();
        }