源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c#冒泡排序算法示例

  • 时间:2021-03-28 21:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#冒泡排序算法示例
[u]复制代码[/u] 代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 冒泡排序 {     class Program     {         static void swap( ref int  atemp, ref int  btemp)//注意ref的使用         {             int temp = atemp;             atemp = btemp;             btemp = temp;         }         static void Main(string[] args)         {             int temp=0;             int[]arr={23,44,66,76,98,11,3,9,7};             Console.WriteLine("排序前的数组:");             foreach(int item in arr)             {                 Console.Write(item+" ");             }             Console.WriteLine();             for(int i=0;i<arr.Length-1;i++)             {                 for(int j=0;j<arr.Length-1-i;j++)                 {                     if (arr[j] > arr[j + 1])                           swap( ref  arr[j], ref arr[j + 1]);                 }             }            Console.WriteLine("排序后的数组:");            foreach(int item in arr)            {                Console.Write(item+" ");             }             Console.WriteLine();             Console.ReadKey();         }     } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部