选择排序

来源:互联网 发布:mac翻墙用什么软件好 编辑:程序博客网 时间:2024/05/17 04:51
class Program    {        static void Main(string[] args)        {            int[] test = new int[5];            for (int i = 0; i < 5; i++)            {                test[i] = Convert.ToInt32(Console.ReadLine());            }            selectsort(test, 5);            foreach (int a in test)            {                Console.Write(a + " ");            }            Console.WriteLine();                    }        static public void selectsort(int[] array, int length)        {            int i=0,j,min,temp_array,temp;            while (i < length - 1)            {                min = array[i];                temp = i;                for (j = i + 1; j < length; j++)                {                    if (array[j] < min)                    {                        min=array[j];                        temp = j;                    }                }                temp_array=array[i];                array[i] = array[temp];                array[temp] = temp_array;                i++;            }        }            }

0 0
原创粉丝点击