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