数组 数组反转,排序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 数据反转
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strAllay = { "小米", "华为", "oppo", "vivo", "魅族","苹果"};
            string s;
            for (int i = 0; i < strAllay.Length / 2; i++)//strAllay.Length/2是因为经过(将数组的长度值除以2)次就可以将数组成员进行反转了
            {
                s = strAllay[i];
                strAllay[i] = strAllay[strAllay.Length - 1 - i];//如果i等于数组第一项值(小米)的时候,将它与最后一个值(苹果)互换。
                strAllay[strAllay.Length - 1 - i] = s;
            }
            foreach (string ss in strAllay)
            {
                Console.Write(ss+" " );
            }
            Console.ReadKey();
            
        }
    }
}

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 数组
{
    class Program
    {
        static void Main(string[] args)
        {
            //输出一个数组里的最大的数值;
            /*
            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);
             **/
            //按大小顺序输出数组的值
            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();

        }
    }
}

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值