C# -- 冒泡排序


C# -- 冒泡排序

1. C#代码

 1             int[] num = { 3, 5, 7, 1, 2, 13, 9, 4, 6, 11, 22, 44, 33, 14, 43, 41, 5, 868, 476, 34535, 345, 46, 47, 47, 848 };
2 for (int i = 0; i < num.Length - 1; i++) 3 { 4 for (int j = num.Length - 1; j > i; j--) 5 { 6 if (num[j] < num[j - 1]) 7 { 8 int temp = num[j]; 9 num[j] = num[j - 1]; 10 num[j - 1] = temp; 11 } 12 } 13 } 14 Console.WriteLine("排序后的数组:"); 15 for (int k = 0; k < num.Length; k++) 16 { 17 Console.Write("{0},", num[k]); 18 } 19 20 Console.ReadKey();

 2. 运行结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM