Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 低效的数据排序算法_C#_Excel_Sorting - Fatal编程技术网

C# 低效的数据排序算法

C# 低效的数据排序算法,c#,excel,sorting,C#,Excel,Sorting,我目前有一个excel电子表格,其中包含许多列 比如说 Id Name Address Class School SchoolAddress 我想使用C#脚本将数据拆分为多张表,其中班级学校和学校地址将用作分组。类似于SQL分组依据 我目前有2个用于循环 (for int i = 1; i <= range.rows.count; i++) { (for int a = 1; a <= range.rows.count; a++) //stores them

我目前有一个excel电子表格,其中包含许多列

比如说

Id  Name  Address  Class School SchoolAddress
我想使用C#脚本将数据拆分为多张表,其中班级学校和学校地址将用作分组。类似于SQL
分组依据

我目前有2个
用于
循环

(for int i = 1; i <= range.rows.count; i++)
{ 
   (for int a = 1; a <= range.rows.count; a++)

   //stores them in an array list and splits them
   //takes the Class school and school Address column to compare against
}

(对于int i=1;i算法的名称是BubbleSort,速度非常慢。
这是快速排序算法,是最快的排序算法之一,它的复杂度是O(n logn)。我只将其用于排序数组

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Quicksort
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an unsorted array of string elements
            string[] unsorted = { "z","e","x","c","m","q","a"};

            // Print the unsorted array
            for (int i = 0; i < unsorted.Length; i++)
            {
                Console.Write(unsorted[i] + " ");
            }

            Console.WriteLine();

            // Sort the array
            Quicksort(unsorted, 0, unsorted.Length - 1);

            // Print the sorted array
            for (int i = 0; i < unsorted.Length; i++)
            {
                Console.Write(unsorted[i] + " ");
            }

            Console.WriteLine();

            Console.ReadLine();
        }

        public static void Quicksort(IComparable[] elements, int left, int right)
        {
            int i = left, j = right;
            IComparable pivot = elements[(left + right) / 2];

            while (i <= j)
            {
                while (elements[i].CompareTo(pivot) < 0)
                {
                    i++;
                }

                while (elements[j].CompareTo(pivot) > 0)
                {
                    j--;
                }

                if (i <= j)
                {
                    // Swap
                    IComparable tmp = elements[i];
                    elements[i] = elements[j];
                    elements[j] = tmp;

                    i++;
                    j--;
                }
            }

            // Recursive calls
            if (left < j)
            {
                Quicksort(elements, left, j);
            }

            if (i < right)
            {
                Quicksort(elements, i, right);
            }
        }

    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
名称空间快速排序
{
班级计划
{
静态void Main(字符串[]参数)
{
//创建字符串元素的未排序数组
字符串[]未排序={“z”、“e”、“x”、“c”、“m”、“q”、“a”};
//打印未排序的数组
for(int i=0;iif(我感谢您考虑了逻辑效率,但您的语法不正确。