数据结构——简单的冒泡排序

来源:互联网 发布:hermitian矩阵 编辑:程序博客网 时间:2024/06/05 14:29
 //冒泡排序            int []scores = {10,20,144,24,574,2,56,66,59,45,4,5,6,8,4,55,41,40};            for (int i = 0; i < scores.Length - 1; i++)            {                for (int j = 0; j < scores.Length - 1 - i; j++)                {                    if (scores[j]>scores[j+1])                    {                        //两两赋值                        int tmp=scores[j];                        scores[j] = scores[j + 1];                        scores[j + 1] = tmp;                    }                }                          }            for (int i = 0; i < scores.Length;i++ )            {                Console.WriteLine(scores[i]);            }            Console.ReadKey();

0 0
原创粉丝点击