国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#數(shù)組反轉(zhuǎn)與排序?qū)嵗治?/h1>
2019-10-29 21:42:50
字體:
供稿:網(wǎng)友
這篇文章主要介紹了C#數(shù)組反轉(zhuǎn)與排序,實(shí)例分析了數(shù)組反轉(zhuǎn)與常見的排序技巧,具有一定參考借鑒價值,需要的朋友可以參考下
 

本文實(shí)例分析了C#數(shù)組反轉(zhuǎn)與排序的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

C#數(shù)組反轉(zhuǎn)

復(fù)制代碼代碼如下:
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
  
namespace 數(shù)據(jù)反轉(zhuǎn)  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            string[] strAllay = { "毛澤東", "李世民", "秦始皇", "成吉思汗", "習(xí)近平","鄧小平"};  
            string s;  
            for (int i = 0; i < strAllay.Length / 2; i++)//strAllay.Length/2是因?yàn)榻?jīng)過(將數(shù)組的長度值除以2)次就可以將數(shù)組成員進(jìn)行反轉(zhuǎn)了  
            {  
                s = strAllay[i];  
                strAllay[i] = strAllay[strAllay.Length - 1 - i];//如果i等于數(shù)組第一項(xiàng)值(毛澤東)的時候,將它與最后一個值(鄧小平)互換。  
                strAllay[strAllay.Length - 1 - i] = s;  
            }  
            foreach (string ss in strAllay)  
            {  
                Console.Write(ss+" " );  
            }  
            Console.ReadKey();  
        }  
    }  
}

C#數(shù)組排序:
復(fù)制代碼代碼如下:
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
  
namespace 數(shù)組  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            //輸出一個數(shù)組里的最大的數(shù)值;  
            /* 
            int[] arr = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 }; 
            int max = 0; 
            for (int i = 0; i < arr.Length - 1; i++) 
            { 
                if (arr[i] > max) 
                { 
                    max = arr[i]; 
                } 
            } 
            Console.WriteLine(max); 
             **/  
            //按大小順序輸出數(shù)組的值  
            int[] list = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 ,100,25,38};  
            /* 
                for (int i = 0; i < list.Length-1; i++) 
                  { 
                      for (int j = i+1; j < list.Length; j++) 
                      { 
                          if (list[i] > list[j]) 
                          { 
                             int temp = list[i]; 
                             list[i] = list[j]; 
                             list[j] = temp; 
                         } 
                     } 
                 }*/  
                /// <summary>  
         /// 插入排序法  
         /// </summary>  
         /// <param name="list"></param>  
          
             for (int i = 1; i < list.Length; i++)  
              {  
                 int t = list[i];  
                 int j = i;  
                 while ((j > 0) && (list[j - 1] > t))  
                 {  
                     list[j] = list[j - 1];  
                     --j;  
                 }  
                 list[j] = t;  
             }  
  
                foreach (int forStr in list)  
                {  
                    Console.Write(forStr + " ");  
                }  
            Console.ReadKey();  
        }  
    }  
}

 

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

主站蜘蛛池模板: 大港区| 新乡县| 九龙城区| 雅江县| 巴南区| 东至县| 白玉县| 荔波县| 金坛市| 芮城县| 肥城市| 无极县| 瑞金市| 中方县| 遵化市| 南丰县| 茶陵县| 墨竹工卡县| 灵宝市| 凌云县| 宜州市| 闽侯县| 会宁县| 灵台县| 彭山县| 潮安县| 建瓯市| 平安县| 监利县| 永寿县| 饶阳县| 蓬莱市| 云梦县| 兴安县| 松潘县| 鸡泽县| 丽江市| 卫辉市| 都昌县| 自治县| 象山县|