Exemple #1
0
    public static void Main(string[] args)
    {
        List <int> numbers = FunctionsCollection.ReadIntListInRangeUptoEmptyLine();

        numbers.Sort();

        Console.WriteLine("The sorted list is:");
        FunctionsCollection.PrintIntList(numbers);
    }
Exemple #2
0
    public static void Main(string[] args)
    {
        List <int> numbers            = FunctionsCollection.ReadIntListInRangeUptoEmptyLine();
        List <int> longestSubsequence = GetLongestSubsequence(numbers);

        Console.WriteLine("The longest subsequence in the list is:");
        FunctionsCollection.PrintIntList(longestSubsequence);

        // For more test see the test class ListMethodsTest.cs
    }
    public static void Main(string[] args)
    {
        Console.WriteLine("We expect positive numbers!");
        List <int> numberCollection = FunctionsCollection.ReadIntListInRangeUptoEmptyLine(1, int.MaxValue);

        long sumNumbers = CalcIntCollectionSum(numberCollection);

        Console.WriteLine("The collection sum is: {0}", sumNumbers);

        double averageNumbers = CalcIntCollectionAverage(numberCollection);

        Console.WriteLine("The collection average is: {0}", averageNumbers);
    }
Exemple #4
0
    public static void Main(string[] args)
    {
        int[] numbers = FunctionsCollection.ReadIntListInRangeUptoEmptyLine().ToArray();
        Dictionary <int, int> numbersCount = FunctionsCollection.GetNumbersCount(numbers);

        int?majorant = FindMajorant(numbersCount, numbers.Length);

        if (majorant == null)
        {
            Console.WriteLine("There is no majorant of that sequence!");
        }
        else
        {
            Console.WriteLine("The majorant is: {0}", majorant);
        }
    }
    public static void Main(string[] args)
    {
        Console.WriteLine("We expect numbers in the range [0 .. 1000]");
        int[] numbers = FunctionsCollection.ReadIntListInRangeUptoEmptyLine(0, 1000).ToArray();
        Dictionary <int, int> numbersCount = FunctionsCollection.GetNumbersCount(numbers);

        Console.WriteLine("The number occurances count is:");
        foreach (KeyValuePair <int, int> numberCount in numbersCount)
        {
            if (numberCount.Value == 1)
            {
                Console.WriteLine("{0} -> {1} time", numberCount.Key, numberCount.Value);
            }
            else
            {
                Console.WriteLine("{0} -> {1} times", numberCount.Key, numberCount.Value);
            }
        }
    }
    // Tests
    public static void Main(string[] args)
    {
        ADTStack <int> testStack = new ADTStack <int>(2);

        Debug.Assert(testStack.Count == 0, "The stack count is not 0!");

        Console.WriteLine("Fill the stack with integers.");
        Console.WriteLine("Please enter more then 2 values to force it to resize.");
        Console.WriteLine(new string('-', 30));

        List <int> userData = FunctionsCollection.ReadIntListInRangeUptoEmptyLine();

        for (int i = 0; i < userData.Count; i++)
        {
            testStack.Push(userData[i]);
        }

        Debug.Assert(testStack.Count == userData.Count, "The stack count is not equal to the number of values entered!");
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("The stack count is: {0}", testStack.Count);

        Console.WriteLine(new string('-', 30));
        try
        {
            Console.WriteLine("Read last element by Peek(): {0}", testStack.Peek());
        }
        catch (InvalidOperationException)
        {
            Console.WriteLine("The stack is empty so Peek() throws an InvalidOperationException!");
        }

        Console.WriteLine(new string('-', 30));
        Console.WriteLine("Read the stack by using Pop():");

        for (int i = testStack.Count - 1; i >= 0; i--)
        {
            Console.WriteLine("{0} : {1}", i, testStack.Pop());
        }

        Debug.Assert(testStack.Count == 0, "The stack count is not 0!");
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("The stack count is: {0}", testStack.Count);
    }
Exemple #7
0
    public static void Main(string[] args)
    {
        ADTQueue <int> testQueue = new ADTQueue <int>();

        Debug.Assert(testQueue.Count == 0, "The queue count is not 0!");

        Console.WriteLine("Fill the queue with integers!");
        Console.WriteLine(new string('-', 30));

        List <int> userData = FunctionsCollection.ReadIntListInRangeUptoEmptyLine();

        for (int i = 0; i < userData.Count; i++)
        {
            testQueue.Enqueue(userData[i]);
        }

        Debug.Assert(testQueue.Count == userData.Count, "The queue count is not equal to the number of values entered!");
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("The queue count is: {0}", testQueue.Count);

        Console.WriteLine(new string('-', 30));
        try
        {
            Console.WriteLine("Read first item by Peak(): {0}", testQueue.Peek());
        }
        catch (InvalidOperationException)
        {
            Console.WriteLine("The queue is empty so Peek() throws an InvalidOperationException!");
        }

        Console.WriteLine(new string('-', 30));
        Console.WriteLine("Read the queue by using Dequeue():");
        for (int i = testQueue.Count - 1; i >= 0; i--)
        {
            Console.WriteLine("{0} : {1}", i, testQueue.Dequeue());
        }

        Debug.Assert(testQueue.Count == 0, "The queue count is not 0!");
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("The queue count is: {0}", testQueue.Count);
    }