Some. NET and SQL questions 2 (with answers)

Source: Internet
Author: User
  1. The factorial of N to implement the algorithm
    Code        public static int N(int n)        {            if (n == 1)            { return 1; }            else            {                return n * N(n - 1);            }        }

  2. Two sorted arrays are combined into a new array in order of size to implement the algorithm.
    Code   public static void Composite(int[] a, int[] b)        {            int[] newArray = new int[a.Length + b.Length];            int count = a.Length + b.Length;            int aIndex = 0;            int bIndex = 0;            for (int i = 0; i < count; i++)            {                if (aIndex >= i)                {                    newArray[i] = a[aIndex];                    continue;                }                if (bIndex >= i)                {                    newArray[i] = b[bIndex];                    continue;                }                if (a[aIndex] <= b[bIndex])                {                    newArray[i] = a[aIndex];                    aIndex++;                }                else                {                    newArray[i] = b[bIndex];                    bIndex++;                }                Console.WriteLine(newArray[i]);            }        }

  3. Write all the combinations of 1, 2, 2, 4, 5, but 4 cannot be in 3rd bits, and 3 and 5 cannot be adjacent.
    Code   public static List<string> listStr = new List<string>();        public static void OutputConposition()        {            char[] arr = { '1', '2', '2', '3', '4', '5' };            string str = new string(arr);            Function(arr, 0, 5);        }        public static void Function(char[] c, int begin, int end)        {            if (begin == end)            {                string str = new string(c);                if (str[2] == '4')                { return; }                if (str.Contains("35") || str.Contains("53"))                { return; }                listStr.Add(str);                return;            }            for (int i = begin; i <= end; i++)            {                Swap(c, begin, i);                Function(c, i + 1, end);                Swap(c, begin, i);            }        }        public static void Swap(char[] arr, int a, int b)        {            char temp;            temp = arr[a];            arr[a] = arr[b];            arr[b] = temp;        }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.