Example #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();
        }
        static void RunProgram(ref bool programRunning)
        {
            int x = InputHandling.ReadValue("Number to calculate the sum: ");

            OutputHandling.Message("The sum of the digits of " + x + " is: " + SumOfDigits.Sum(x));
            OutputHandling.Question("Do you want to calculate the sum of the digits of another number? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Example #3
0
        static void RunProgram(ref bool programRunning)
        {
            int n = InputHandling.ReadValue("Number to print from fibonacci sequence, starting at 1: ");

            Console.WriteLine(Fibonacci.FindFiboInSequence(n));
            OutputHandling.Question("Do you want to find another number in a fibonacci sequence? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
        static void RunProgram(ref bool programRunning)
        {
            int x = InputHandling.ReadValue("Type in a value to calculate it's factorial: ");

            Console.WriteLine("How do you want to calculate the factorial? R - Recursion, I - Iteration");
            Factorial.CalculateFactorial(x);
            OutputHandling.Question("Do you want to determine the factorial of another number? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
        static void RunProgram(ref bool programRunning)
        {
            int n = InputHandling.ReadValue("Number to display set bits: ");

            int[] nToBase2 = BaseConversion.ConvertBase10ToBaseX(n, 2);
            OutputHandling.Message("The number of bits that are set for " + n + " is " + SetBits.CountSetBits(n));
            OutputHandling.PrintArray(nToBase2, nToBase2.Length, "Representation of " + n + " in base 2 is: ", "", "0b", false);
            OutputHandling.Question("Do you want to calculate the number of set bits of a nother number? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
        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();
        }
 public static void TryOverWrite(ref string fileName, Uri uri)
 {
     if (File.Exists(fileName))
     {
         OutputHandling.Question($"There is already an existing file called {fileName}. Do you want to overwrite it? Y / N");
         if (!InputHandling.QuestionOptions(false))
         {
             Rename(ref fileName, uri);
         }
     }
 }
        static void Main(string[] args)
        {
            string url = InputHandling.ReadString("Url to download from: ");

            Downloader.Download(url);
            OutputHandling.Question("Do you want to download another file? Y / N");
            if (InputHandling.QuestionOptions())
            {
                Main(args);
            }
        }
        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();
        }
Example #10
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();
        }
        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();
        }
        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();
        }
        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();
        }
        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();
        }
Example #15
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();
        }
        public static void GetPublisherIdId()
        {
            int publisherId = InputHandling.ReadValue("Publisher Id to delete: ");

            BooksCrud.DeletePublisher(publisherId);
            OutputHandling.Question("Do you want to delete another publisher? Y / N");
            if (InputHandling.QuestionOptions())
            {
                GetPublisherIdId();
            }
            else
            {
                ProgramFlowHandling.Exit("Thank you... bye!");
                dbBooksConn.Dispose();
            }
        }
Example #17
0
        static void RunProgram(ref bool programRunning)
        {
            int year = InputHandling.ReadValue("Year to check if it is leap or not: ");

            if (Leap.IsLeap(year))
            {
                OutputHandling.Message(year + " is a leap year", ConsoleColor.Green);
            }

            else
            {
                OutputHandling.Message(year + " is not a leap year", ConsoleColor.Red);
            }

            OutputHandling.Question("Do you want to check another year if it is leap? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Example #18
0
        static void RunProgram(ref bool programRunning)
        {
            int  n         = InputHandling.ReadValue("Number to check if it is ARMSTRONG or NOT: ");
            bool armstrong = Armstrong.IsArmstrong(n);

            if (armstrong)
            {
                OutputHandling.Message(n + " is an armstrong number", ConsoleColor.Green);
            }

            else
            {
                OutputHandling.Message(n + " is not an armstrong number", ConsoleColor.Magenta);
            }

            OutputHandling.Question("Do you want to check another number if it is an Armstrong number? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
        static void RunProgram(ref bool programRunning)
        {
            int  n            = InputHandling.ReadValue("Number to check if it is a palindrome or not: ");
            bool isPalindrome = Palindrome.IsPalindrome(n);

            if (isPalindrome)
            {
                OutputHandling.Message(n + " is a palindrome!", ConsoleColor.Green);
            }

            else
            {
                OutputHandling.Message(n + " is not a palindrome!", ConsoleColor.Red);
            }

            OutputHandling.Question("Do you want to check if another number is a palindrome? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Example #20
0
        static void RunProgram(ref bool programRunning)
        {
            OutputHandling.Question("First String: ", false);
            string firstString = Console.ReadLine();

            int[] firstStringFreqArray = FrequencyOfElements.GenerateFrequencyArray(firstString, firstString.Length);

            OutputHandling.Question("Second String: ", false);
            string secondString = Console.ReadLine();

            int[] secondStringFreqArray = FrequencyOfElements.GenerateFrequencyArray(secondString, secondString.Length);

            bool isAnagram = Anagram.FindAnagram(firstStringFreqArray, secondStringFreqArray);

            Anagram.PrintAnagramResult(isAnagram, firstString, secondString);

            OutputHandling.Question("Do you want to check other two strings for anagram?");
            programRunning = InputHandling.QuestionOptions();
        }
Example #21
0
        static void RunProgram(ref bool programRunning)
        {
            // Take string as input
            OutputHandling.Message("Type in a string to check for duplicate characters: ", ConsoleColor.Green, false);
            string s = Console.ReadLine();

            // Remove extra spaces from string and tabs
            string sClean = StringManipulation.RemoveExtraSpaces(s);

            // Convert String to char array
            char[] sToChar    = Conversion.ConvertToCharArray(sClean);
            int    sToCharLen = sToChar.Length;

            // Remove duplicate characters
            ArrayManipulation.RemoveDuplicates(ref sToChar, ref sToCharLen);

            OutputHandling.PrintArray(sToChar, sToCharLen, "The string without duplicates is: ", "", newLine: false);
            OutputHandling.Question("Do you want to remove duplicate characters in another string? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
        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();
        }
Example #23
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();
        }